java写的界面,JTable无法显示数据库数据,求大神帮助!! 100
publicvoidmouseClicked(MouseEvente){Stringurl="jdbc:sqlserver://localhost:1433;Databa...
public void mouseClicked(MouseEvent e)
{
String url="jdbc:sqlserver://localhost:1433; DatabaseName=dormitoryMG";
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Statement st;
Connection con;
try
{
Class.forName(driver);//加载驱动
}
catch(ClassNotFoundException event)
{
System.out.print("无法创建驱动程式实体!");
}
try
{
con=DriverManager.getConnection(url,"sa","");
con.setAutoCommit(true);
st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * from student ");
int sno,sage,dno,bno;
String sname,ssex,sid,sphone,saddress,spassword;
// 将查询获得的记录数据,转换成适合生成JTable的数据形式
Object[][] info = new Object[10][10];
int i = 0;
rs=st.executeQuery("SELECT * from student ");
for(i=0;i<=10;i++)
{
if(rs.next())
{
info[i][0] = Integer.valueOf( rs.getInt("sno"));
info[i][1] = rs.getString("sname");
info[i][2] = rs.getString("ssex");
info[i][3] = Integer.valueOf( rs.getInt("sage") );
info[i][4] = rs.getString("sid");
info[i][5] = Integer.valueOf(rs.getInt("sphone"));
info[i][6] = rs.getString("saddress");
info[i][7] = rs.getString("spassword");
info[i][8] = Integer.valueOf(rs.getInt("dno"));
info[i][9] = Integer.valueOf(rs.getInt("bno"));
}
}
st.close();
con.close();
// 定义表头
String[] title = {"学号","姓名","性别","年龄","身份证号","联系电话","家庭住址","登陆密码","寝室号","楼号"};
table_1=new JTable(info,title);
catch(SQLException e1)
{
System.out.println("异常"+e1);
}
}
});
PS:运行后界面显示就是一片空白,怎么点按钮都没反应,求大手! 展开
{
String url="jdbc:sqlserver://localhost:1433; DatabaseName=dormitoryMG";
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Statement st;
Connection con;
try
{
Class.forName(driver);//加载驱动
}
catch(ClassNotFoundException event)
{
System.out.print("无法创建驱动程式实体!");
}
try
{
con=DriverManager.getConnection(url,"sa","");
con.setAutoCommit(true);
st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * from student ");
int sno,sage,dno,bno;
String sname,ssex,sid,sphone,saddress,spassword;
// 将查询获得的记录数据,转换成适合生成JTable的数据形式
Object[][] info = new Object[10][10];
int i = 0;
rs=st.executeQuery("SELECT * from student ");
for(i=0;i<=10;i++)
{
if(rs.next())
{
info[i][0] = Integer.valueOf( rs.getInt("sno"));
info[i][1] = rs.getString("sname");
info[i][2] = rs.getString("ssex");
info[i][3] = Integer.valueOf( rs.getInt("sage") );
info[i][4] = rs.getString("sid");
info[i][5] = Integer.valueOf(rs.getInt("sphone"));
info[i][6] = rs.getString("saddress");
info[i][7] = rs.getString("spassword");
info[i][8] = Integer.valueOf(rs.getInt("dno"));
info[i][9] = Integer.valueOf(rs.getInt("bno"));
}
}
st.close();
con.close();
// 定义表头
String[] title = {"学号","姓名","性别","年龄","身份证号","联系电话","家庭住址","登陆密码","寝室号","楼号"};
table_1=new JTable(info,title);
catch(SQLException e1)
{
System.out.println("异常"+e1);
}
}
});
PS:运行后界面显示就是一片空白,怎么点按钮都没反应,求大手! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询