我用eclipse1.5.0, sql server 2000编程时,出现
java.lang.ClassCastException: com.microsoft.jdbc.base.BaseStatement
at Design.testsql.getConnection(testsql.java:37)
at Design.testsql.displayDbProperties(testsql.java:60)
at Design.testsql.main(testsql.java:109)
Error Trace in getConnection() : com.microsoft.jdbc.base.BaseStatement
的错误,我刚接触这方面的内容,请大家指点:
这是我的程序,
package Design;
import java.beans.Statement;
import java.sql.*;
import java.sql.ResultSet;
public class testsql{
private java.sql.Connection con =null;
private final String url = "jdbc:microsoft:sqlserver:// ";
private final String serverName= "192.168.0.34 ";
private final String portNumber = "1433 ";
private final String databaseName= "TTSQL ";
private final String userName = "sa ";
private final String password = "onetwo ";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor ";
String query = "Select Teacher_Name from Teacher_INFO ";
// Constructor
public testsql(){}
private String getConnectionUrl(){
return url+serverName+ ": "+portNumber+ ";databaseName= "+databaseName+ ";selectMethod= "+selectMethod+ "; ";
}
private java.sql.Connection getConnection(){
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println( "创建连接对像成功! " );
Statement st = (Statement) con.createStatement();
System.out.println( "创建Statement成功! " );
ResultSet rs = ((java.sql.Statement) st).executeQuery(query);
System.out.println( "操作数据表成功! " );
System.out.println( "----------------! " );