I am new to JDBC and using a tutorial to create my first connection. However, I am getting the below error -
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
import java.sql.*;
public class Demo {
public static void main(String[] args) throws Exception {
String url="jdbc:mysql://localhost:3306//demo";
String user="root";
String password="vishal123";
String query = "select * from student";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,user,password);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
String name = rs.getString("user_name");
System.out.println(name);
st.close();
con.close();
}
}
Do let me know if you need any more details to solve the problem.