[求助]为什么我的程序能运行,却得不到数据库中的数据
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();
}
}
请问各位大侠怎么解决啊??谢谢
----------------解决方案--------------------------------------------------------
有什么异常信息?
一般连接SqlServer2000需要打SP3或者SP4的补丁,把验证模式改为混合验证,加上驱动包。
----------------解决方案--------------------------------------------------------
我补丁打了啊~连接数据库也成功了啊!可是这个程序却得不到数据啊!!
----------------解决方案--------------------------------------------------------