0
<%@ page import="java.sql.*" %>
<% String uname=request.getParameter("n");
String pwd=request.getParameter("pwd");
String country=request.getParameter("cnt");

try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/my_db","root","");
Statement st = conn.createStatement();
int i=st.executeUpdate("insert into test values('"+uname+"','"+pwd+"','"+country+"')");

out.println("Registration Successful");
}
catch(Exception e)
{
out.println(e);
}

%>

this is code for jdbc connection with database .i am facing error com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: even i have installed mysql 8 version

  • 1
    Please provide the full exception stacktrace (use `e.printStackTrace()`), not just the name of the exception. – Mark Rotteveel Jun 19 '21 at 07:36
  • Are you having the same version of MySql Connector and MySql? Refer this https://stackoverflow.com/a/50186856/15590269 – Sam Joshua Jun 19 '21 at 09:49
  • @SamJoshua You don't need to have the same version of MySQL Connector/J as your MySQL version. My answer you link is that if you are using MySQL 8, then you need to have a sufficiently recent version of MySQL Connector/J. – Mark Rotteveel Jun 19 '21 at 14:51
  • @MarkRotteveel Yes, you are right "If you are using MySQL 8, then you need to have a sufficiently recent version of MySQL Connector/J" – Sam Joshua Jun 20 '21 at 03:10

0 Answers0