?? stuinformation.java
字號:
/*
* Sinformation.java
*
* Created on 2007年11月15日, 下午8:55
*/
package javaapplication1;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author mis05
*/
public class Stuinformation extends javax.swing.JPanel {
/** Creates new form Sinformation */
public Stuinformation() {
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=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("\u67e5\u8be2\u5b66\u751f\u4fe1\u606f");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
search(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(74, 74, 74)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 247, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(140, 140, 140)
.add(jButton1)))
.addContainerGap(79, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(34, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(25, 25, 25)
.add(jButton1)
.add(41, 41, 41))
);
}// </editor-fold>//GEN-END:initComponents
private void search(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_search
Statement sql;
try{
Conect conect = new Conect();
sql = conect.dbConn.createStatement();
String number = null;
int temp = 0;
ResultSet rs = sql.executeQuery("select 學生編號 from 學生 where 登錄 =1");
while( rs.next() ) {
number = rs.getObject(1).toString();
}
String query = "select 學生編號,姓名,性別,出生日期,政治面貌,專業名稱 from 學生 where 學生編號 ='"+number+"'";
rs = sql.executeQuery(query);
StringBuffer output = new StringBuffer();
ResultSetMetaData data = rs.getMetaData();
int columns = data.getColumnCount();
rs.next();
output.append( "學生編號\t" + rs.getObject(1) + "\n");
output.append("姓名\t"+rs.getObject(2)+"\n");
output.append("性別\t"+rs.getObject(3)+"\n");
output.append("出生日期\t"+rs.getObject(4)+"\n");
output.append("政治面貌\t"+rs.getObject(5)+"\n");
output.append("專業名稱\t"+rs.getObject(6)+"\n");
String output1 = output.toString();
jTextArea1.setText( output1 );
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);} catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}// TODO add your handling code here:
}//GEN-LAST:event_search
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Stuinformation().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration//GEN-END:variables
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -