各位高手请帮我看一下代码,到底是在哪里出了问题?
我的代码是想从数据库中取出数据,再把那些数据封装成一个Uuser对象,最后把那些对象输出在屏幕上.可是我一运行程序就抛出异常.我看了半天都找不出原因,请各位高手帮我分析一下.多谢!
package hello;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.sql.*;
import com.microsoft.jdbc.sqlserver.*;
public class JTableTest {
//JTable table;
ArrayList arr;
public JTableTest()throws Exception{
try{
String CLASSFORNAME= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String SERVANDDB= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=CMS ";
String USER= "sa ";
String PWD= " ";
Class.forName(CLASSFORNAME).newInstance();
Connection con = DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement statement=con.createStatement();
String isCorrect= "select * from users ";
ResultSet result=statement.executeQuery(isCorrect);
arr=new ArrayList();
while(result.next()){//User是我自己写的一个类
arr.add(new User(result.getString( "User_id "),result.getString( "User_password "),result.getString( "User_name "),Integer.parseInt(result.getString( "User_power "))));
}
//table=new JTable(new tableModel(arr));
}catch(Exception e){
throw e;
}
}
public static void main(String[] args)throws Exception{
try{
JTableTest f=new JTableTest();