I have Java code that looks as follows and a MySQL database running on my machine.
System.out.println("Loading JDBC");
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("JDBC loaded");
System.out.println("Establishing connection");
myConnection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:1186/dbname","username","password");
System.out.println("Connection established");
However, the output I get is the following:
Loading JDBC
JDBC loaded
Establishing connection
and then nothing? it doesn't report an error connecting, so it must be connected.
What's going on? why isn't it moving to the next line of code?
I'd appreciate any help
解决方案
Few points:
What is the name of database? If you are trying to run the code shown above, than database name must be "dbname", username must be "username" and password must be "password".
Is your MySQL listening to port 1186? I am just wondering as generally at the time of installation default port is set to 3306.
If you want to follow steps involved in connecting MySQL with JDBC, you can take a look to this tutorial for JDBC Steps.
Jwalant