?? 用戶查詢.java
字號:
/*
* 用戶查詢.java
*
* Created on 2008年6月22日, 下午5:00
*/
package javaapplication1;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Administrator
*/
public class 用戶查詢 extends javax.swing.JFrame {
Connection con;//創建對象
Statement sql;
ResultSet rs;
/** Creates new form 用戶查詢 */
public 用戶查詢() {
setTitle("用戶查詢");
setBounds(300,50,40,20);
setResizable(false);
initComponents();
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代碼 ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jScrollPane2 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 204, 204));
jTable1.setBackground(new java.awt.Color(255, 204, 153));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"姓名", "性別", "身份證", "出發地", "目的地", "旅行時間", "車型要求", "成功訂票"
}
));
jScrollPane1.setViewportView(jTable1);
jTable2.setBackground(new java.awt.Color(255, 204, 153));
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"姓名", "性別", "身份證", "出發地", "目的地", "旅行時間", "車型要求", "成功訂票"
}
));
jScrollPane2.setViewportView(jTable2);
jButton1.setBackground(new java.awt.Color(204, 255, 204));
jButton1.setText("\u5df2\u8ba2\u7968");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(204, 255, 204));
jButton2.setText("\u6210\u529f\u8ba2\u7968");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBackground(new java.awt.Color(204, 255, 204));
jButton3.setText("\u4e0a\u4e00\u5c42");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setBackground(new java.awt.Color(204, 255, 204));
jButton4.setText("\u5173\u95ed");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(20, 20, 20)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 555, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 29, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton2)
.add(jButton1))
.add(12, 12, 12))
.add(jPanel1Layout.createSequentialGroup()
.add(173, 173, 173)
.add(jButton3)
.add(166, 166, 166)
.add(jButton4)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 152, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(14, 14, 14)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel1Layout.createSequentialGroup()
.add(50, 50, 50)
.add(jButton1)
.add(137, 137, 137)
.add(jButton2)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 54, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton3)
.add(jButton4))
.add(25, 25, 25))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 將在此處添加您的處理代碼:
String[] col = { "姓名", "性別", "身份證","出發地","目的地","旅行時間","車型要求","成功訂票" };
DefaultTableModel mm= new DefaultTableModel(col,0);
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}//建立JDBC-ODBC的橋接器}
catch(ClassNotFoundException e) { System.out.println(""+e); }
try{
con=DriverManager.getConnection("jdbc:odbc:車票預訂系統","","");//連接到數據庫
sql=con.createStatement();//向數據庫發送SQL語句
rs=sql.executeQuery("use 車票預訂系統 select * from 用戶信息表 where 成功訂票='是'");
while(rs.next()) {
String name=rs.getString(1);
String sex=rs.getString(2);
String id=rs.getString(3);
String from=rs.getString(4);
String to=rs.getString(5);
String time=rs.getString(6);
String type=rs.getString(7);
String ok=rs.getString(8);
String[] str_row={name,sex,id,from,to,time,type,ok};
mm.addRow(str_row);//添加在表模板中
} jTable1.setModel(mm);
}
catch(SQLException e) {System.out.println(e);}
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 將在此處添加您的處理代碼:
String[] col = { "姓名", "性別", "身份證","出發地","目的地","旅行時間","車型要求","成功訂票" };
DefaultTableModel mm= new DefaultTableModel(col,0);
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}//建立JDBC-ODBC的橋接器}
catch(ClassNotFoundException e) { System.out.println(""+e); }
try{
con=DriverManager.getConnection("jdbc:odbc:車票預訂系統","","");//連接到數據庫
sql=con.createStatement();//向數據庫發送SQL語句
rs=sql.executeQuery("use 車票預訂系統 select * from 用戶信息表 where 成功訂票='否'");
while(rs.next()) {
String name=rs.getString(1);
String sex=rs.getString(2);
String id=rs.getString(3);
String from=rs.getString(4);
String to=rs.getString(5);
String time=rs.getString(6);
String type=rs.getString(7);
String ok=rs.getString(8);
String[] str_row={name,sex,id,from,to,time,type,ok};
mm.addRow(str_row);//添加在表模板中
} jTable2.setModel(mm);
}
catch(SQLException e) {System.out.println(e);}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO 將在此處添加您的處理代碼:
this.dispose();
}//GEN-LAST:event_jButton4ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO 將在此處添加您的處理代碼:
new user_imformation().setVisible(true);
this.dispose();
}//GEN-LAST:event_jButton3ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new 用戶查詢().setVisible(true);
}
});
}
// 變量聲明 - 不進行修改//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTable jTable2;
// 變量聲明結束//GEN-END:variables
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -