我的代码不能用java和jsp plz帮帮我
public class DbConnect {
Connection conn = null;
ResultSet rst;
java.sql.Statement stmt;
String url="jdbc:mysql://localhost:3306/";
String dbName="teljo";
String driver="com.mysql.jdbc.Driver";
String userName="root";
String password="";
public Connection getConnect(){
try {
Class.forName(driver).newInstance();
System.out.println("driver loaded sucessfully");
conn=DriverManager.getConnection(url + dbName,userName,password);
System.out.println("connect to the data base");
}
catch (ClassNotFoundException ce) {
System.out.println("driver loading failed"+ ce);
}
catch (Exception e) {
System.out.println("error in connection to database");
}
return conn;
}
}
这是我的连接代码db class。 mysql连接notconnect是做什么的?我使用eclipse IDE, 输出就是这个
driver loading failedjava.lang.ClassNotFoundException: com.mysql.jdbc.Driverjava.lang.NullPointerException
答案 0 :(得分:0)
请将外部MySQL Connector / J添加到您的项目中。这些可以解决问题。
下载mysql jdbc jar的链接:https://dev.mysql.com/downloads/connector/j/