Вот код, который я пытался подключить, но ничего (данные) не поступает в строки базы данных MySQL.
Код: Выделить всё
public class DBConnection{
private static final long serialVersionUID = 1L;
private final Connection connection;
private final String dbURL = "jdbc:mysql://localhost:3306/Servlet";
private final String user = "root";
private final String pwd = "";
public DBConnection() throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection(dbURL, user, pwd);
}
public Connection gC(){
return this.connection;
}
}
Код: Выделить всё
public class ReServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try{
String uName=req.getParameter("uName");
String uEmail=req.getParameter("uEmail");
String uPass=req.getParameter("uPass");
DBConnection conn=new DBConnection();
PreparedStatement ps;
ps = conn.gC().prepareStatement("insert into users(name,email,password) values (?,?,?)");
ps.setString(1, uName);
ps.setString(2, uEmail);
ps.setString(3, uPass);
ps.execute();
}catch(SQLException | ClassNotFoundException se){
se.printStackTrace();
}finally{
}
}
}
Отредактировано
Путем замены se.printStackTrace(); на этот throw new RuntimeException(se); Я получаю это исключение java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Подробнее здесь: https://stackoverflow.com/questions/331 ... va-servlet
Мобильная версия