M
moutocean
Unregistered / Unconfirmed
GUEST, unregistred user!
import java.net.URL;
import java.sql.*;
import java.awt.*;
public class dbTest2{
public static void main(String args[]) {
Connection connection;
Statement statement;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Opening db connection");
connection = DriverManager.getConnection("jdbcdbc:sql_test");//sql_test是ODBC中的一个数据源
statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from stud");
String name = rs.getString("name");
System.out.print( "name: "+name);
}
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
}
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
}
}
}
编译后提示:Cannot connect to this database。跟踪调试发现执行到
String name = rs.getString("name");
后出现SQLException ex:[Microsoft][ODBC Driver Manager] Invalid cursor state。
各位高手,请帮忙!
import java.sql.*;
import java.awt.*;
public class dbTest2{
public static void main(String args[]) {
Connection connection;
Statement statement;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Opening db connection");
connection = DriverManager.getConnection("jdbcdbc:sql_test");//sql_test是ODBC中的一个数据源
statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from stud");
String name = rs.getString("name");
System.out.print( "name: "+name);
}
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
}
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
}
}
}
编译后提示:Cannot connect to this database。跟踪调试发现执行到
String name = rs.getString("name");
后出现SQLException ex:[Microsoft][ODBC Driver Manager] Invalid cursor state。
各位高手,请帮忙!