[求助]为什么我的程序能运行,却得不到数据库中的数据
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
class StudentData extends JDialog implements ActionListener{
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JTextField txtNO=new JTextField(8);
JTextField txtName=new JTextField(10);
JTextField txtSex=new JTextField(2);
JButton first=new JButton("首页");
JButton ok=new JButton("退出");
Statement stmt;
ResultSet rs;
public StudentData(){
setModal(true);
setSize(400,300);
setTitle("学生档案信息查看表");
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xsda","sa","");
stmt=con.createStatement();
rs=stmt.executeQuery("select * from xsdl");
Container content=this.getContentPane();
content.setBackground(Color.DARK_GRAY);
content.setLayout(new GridLayout(4,1));
p1.add(new JLabel("学号:"));
p1.add(txtNO);
p2.add(new JLabel("姓名:"));
p2.add(txtName);
p3.add(new JLabel("性别:"));
p3.add(txtSex);
p4.add(ok);
p4.add(first);
ok.addActionListener(this);
first.addActionListener(this);
content.add(p1);
content.add(p2);
content.add(p3);
content.add(p4);
rs.first();
loadData();
}catch(Exception e){e.printStackTrace();}
setVisible(true);
}
boolean loadData(){
try{
txtNO.setText(rs.getString("classNO"));
txtName.setText(rs.getString("Name"));
txtSex.setText(rs.getString("sex"));
}catch(SQLException e){e.printStackTrace(); return false;}
return true;
}
public void actionPerformed(ActionEvent e){
try{
if(e.getSource()==ok){
dispose();
System.exit(0);
}
else if(e.getSource()==first){
rs.first();
}
loadData();
}catch(Exception er){}
}
public static void main(String args[]){
JFrame.setDefaultLookAndFeelDecorated(true);
Font font=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()){
Object key=keys.nextElement();
if(UIManager.get(key) instanceof Font)
UIManager.put(key,font);
}
StudentData stu=new StudentData();
}
}
请问各位大侠怎么解决啊??谢谢