import java.sql.*;
private String dbDriver="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://localhost:3306;DatabaseName=mytable";
private String user="root";
private String code=""; public Connection Conn(){
Connection conn=null;
try{
Class.forName(dbDriver);
conn=DriverManager.getConnection(url,user,code);
a="true";
}
catch(Exception e){
e.printStackTrace();
}
return conn;
}
在Servlet里设置到mysql的连接,但是conn的返回值总是null,经过测试是
conn=DriverManager.getConnection(url,user,code);
这句出的问题。数据库已经打开了,也没有什么问题。为什么就是出错呢?
private String dbDriver="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://localhost:3306;DatabaseName=mytable";
private String user="root";
private String code=""; public Connection Conn(){
Connection conn=null;
try{
Class.forName(dbDriver);
conn=DriverManager.getConnection(url,user,code);
a="true";
}
catch(Exception e){
e.printStackTrace();
}
return conn;
}
在Servlet里设置到mysql的连接,但是conn的返回值总是null,经过测试是
conn=DriverManager.getConnection(url,user,code);
这句出的问题。数据库已经打开了,也没有什么问题。为什么就是出错呢?
我的是
String url = "jdbc:mysql://localhost:3306/mqney?user=user&password=123456";
conn = DriverManager.getConnection(url);