连接MYSQL数据库问题
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
String url =new String();
url = "mysql://localhost:3306/jb_test?user=root&password=19850503&useUnicode=true&characterEncoding=gb2312 ";
//testDB为你的数据库名
Connection conn = DriverManager.getConnection(url);
Statement stmt= conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from t1 ";
ResultSet rs=stmt.executeQuery(sql);
String tt= " ";
while(rs.next()){
tt = rs.getString( "name ");
jLabel1.setText(tt);
}
调试时当“Connection conn = DriverManager.getConnection(url);”进入异常
DRIVER已经设置正确..请问是什么问题
------解决方案--------------------异常贴出来看
------解决方案--------------------建议使用连接池
------解决方案--------------------应该是 com.jdbc.mysql.Driver 吧,org.gjt.mm.mysql.Driver 是为了兼容以前版本的 JDBC 而保留的,可能不支持游标操作。
------解决方案--------------------package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class T1 {
public static void main(String[] args) throws Exception {
Class.forName( "com.mysql.jdbc.Driver ").newInstance();
String url = "jdbc:mysql://localhost:3306/test?user=root&password=xfu5188 ";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}
}