jdbc问题,请教高手
表tb_business中有数据,但是以下代码中的rs.next()老是返回false数据库是sqlserver2000
public static void main(String[] srg) {
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //加载JDBC驱动
//com.microsoft.jdbc.sqlserver.SQLServerDriver
String dbURL = "jdbc:microsoft:sqlserver://localhost:14330; DatabaseName=db_net"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "123"; //密码
Connection dbConn;
ResultSet rs;
Statement stmt;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
stmt=dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("select name from tb_business");
System.out.println("1");
while(rs.next())
{
System.out.println(rs.getString(1));
}
}
catch(ClassNotFoundException e)
{
System.out.println("加载驱动程序出错");
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
catch(Exception e)
{
System.out.println("出现了好大的错误");
e.printStackTrace();
}
System.out.println("2");
}
} sqlserver2000 jdbc java --------------------编程问答-------------------- "select name from tb_business" tb_business 这个表中是否有name字段?还有name是个关键字,需要这样写"select [name] from tb_business" --------------------编程问答-------------------- 确定输出下你的rs集合是有数据的? --------------------编程问答-------------------- 用stmt=dbConn.createStatement()试试。
补充:Java , Eclipse