为什么我查的数据在表中不显示。

basa188 2010-04-25 02:07:13
public class Select_studentnoPanel extends JPanel {
public Select_studentnoPanel ()
{
try{
jbInit();
}catch(Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.setLayout(null);
this.setBackground(new Color(168,233,216));
button1.setBounds(new Rectangle(314,36,81,23));
button1.setText("退出");
button1.addActionListener(new Exit(this));
label1.setText("学生姓名");
label1.setBounds(new Rectangle(25,38,71,15));
button2.setBounds(new Rectangle(246,38,64,23));
button2.setText("查询");
button2.addActionListener(new Select_no(this));
tsno.setBounds(new Rectangle(108,38,126,20));
list.setBounds(new Rectangle(20,84,442,70));
this.add(button1);
this.add(label1);
this.add(button2);
this.add(tsno);
this.add(list);
this.setVisible(true);
this.setSize(600,600);

}
JButton button1=new JButton();
JButton button2=new JButton();
JLabel label1=new JLabel();
JTextField tsno=new JTextField();
JList list=new JList();
public void button1_actionPerformed(ActionEvent e)
{
this.setVisible(false);
}

public void button2_actionPerformed(ActionEvent e)
{
String sno=tsno.getText().trim();
GradeManager sm=new GradeManager();
Vector v=sm.findStudent(sno);
list.setListData(v);
}


}
class Select_no implements ActionListener
{
private Select_studentnoPanel adaptee;
Select_no(Select_studentnoPanel adaptee)
{
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.button2_actionPerformed(e);
}
}
class Exit implements ActionListener
{
private Select_studentnoPanel adaptee;
Exit(Select_studentnoPanel adaptee)
{
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.button1_actionPerformed(e);
}
}
...全文
50 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
一头头 2010-04-25
  • 打赏
  • 举报
回复
JF 回复内容 回复内容太短了!
basa188 2010-04-25
  • 打赏
  • 举报
回复
public class GradeManager {
public int addStudent(Student s)
{

int i=0;
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ce)
{System.out.println("SQLException:"+ce.getMessage());}
try
{
String url = "jdbc:odbc:class8_10";
String user = "";
String password = "";
Connection con=DriverManager.getConnection(url, user, password);
Statement stmt=con.createStatement();
String sqlstr="insert into student values('"+s.getSno()+"','"+s.getSname()+"','"+s.getSclass()+"','"+s.getSgrade()+"')";
i=stmt.executeUpdate(sqlstr);
stmt.close();
con.close();
}
catch(SQLException e)
{System.out.println("SQLException:"+e.getMessage());}
return i;
}
public int deleteStudent(Student sno)
{
int i=0;
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ce)
{System.out.println("SQLException:"+ce.getMessage());}
try
{
String url = "jdbc:odbc:class8_10";
String user = "";
String password = "";
Connection con=DriverManager.getConnection(url, user, password);
Statement stmt=con.createStatement();
String sqlstr="delete from student where Sno='"+sno+"'";
i=stmt.executeUpdate(sqlstr);
stmt.close();
con.close();
}
catch(SQLException e)
{System.out.println("SQLException:"+e.getMessage());}
return i;
}
public int updateStudent(String sno,String sname,String sclass,String sgrade)
{
int i=0;
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ce)
{System.out.println("SQLException:"+ce.getMessage());}
try
{
String url = "jdbc:odbc:class8_10";
String user = "";
String password = "";
Connection con=DriverManager.getConnection(url, user, password);
Statement stmt=con.createStatement();
String sqlstr="update student set sname='"+sname+"',sclass='"+sclass+"','"+sgrade+"'";
i=stmt.executeUpdate(sqlstr);
stmt.close();
con.close();
}
catch(SQLException e)
{System.out.println("SQLException:"+e.getMessage());}
return i;
}
public Vector findStudent(String sno){
Vector s=null;
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ce)
{System.out.println("SQLException:"+ce.getMessage());}
try
{
String url = "jdbc:odbc:class8_10";
String user = "";
String password = "";
Connection con=DriverManager.getConnection(url, user, password);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student where sno='"+sno+"'");
while(rs.next())
{
System.out.println(
"学号"+rs.getString(1)+"\t"+
"姓名"+rs.getString(2)+"\t"+
"班级 "+rs.getString(3)+"\t"+
"成绩"+rs.getFloat(4)+"\t");
}
stmt.close();
con.close();
}
catch(SQLException e)
{System.out.println("SQLException:"+e.getMessage());}
return s;
}
}

chenluozhi 2010-04-25
  • 打赏
  • 举报
回复
你的代码无法运行。。。GradeManager类跑到哪里了?。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧