读书人

请好手支招

发布时间: 2011-12-19 23:23:36 作者: rapoo

请高手支招!
import java.sql.*;
public class testdb {

/**
* @param args
*/
public static void main(String[] args) throws SQLException,ClassNotFoundException{
// TODO Auto-generated method stub
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
System.out.println( "Driver loaded ");

Connection connection=DriverManager.getConnection( "jdbc:odbc:student ");
System.out.println( "Database connected ");

Statement statement=connection.createStatement();

ResultSet resultSet=statement.executeQuery( "select * from student ");

while(resultSet.next())
System.out.println(resultSet.getString(2)+ "\t "+resultSet.getString(3));
connection.close();


}

}

我运行这段代码的时候弹出一个错误对话框,上面提示说:
The archive:C:/Program Files/Java/jdk1.6.0/lib/jta-spec1_0_1.jar which is referenced by the classpath,does not exist.


[解决办法]
没有添加JDBC驱动中的jar

读书人网 >J2SE开发

热点推荐