我有主页index.jsp。来自 jsp 页面的请求已发送到数据库。但是数据库连接没有发生。它没有给出任何错误并且它给出空白页面。即使我已经使用 tomcatserver 添加了 mysql connector.jar 到库 file.am。谁能帮我解决问题。这是完整的代码
disply.java
public class MyDb {
Connection con;
public Connection getcon() {
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/studentinfo", "root", "adminuser");
} catch (ClassNotFoundException ex) {
Logger.getLogger(MyDb.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(MyDb.class.getName()).log(Level.SEVERE, null, ex);
}
return con;
}
}
最佳答案
您必须将连接对象分配给从 DriverManager 返回的连接
Connection con = null;
....
con = DriverManager.getConnection("jdbc:mysql......
关于mysql - jsp servlet Mysql数据库连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46924964/