Reputation: 5
I am running the following code on a Windows Server box using Java on Eclipse.
Connection conn = null; // connection object
Statement stmt = null; // statement object
ResultSet rs = null; // result set object
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/errorcodes", "myusername", "mypassword");
System.out.println ("Database connection established");
}catch (Exception e){
System.err.println ("Cannot connect to database server");
}
And i keep seeing the "Cannot connect to database server error". Any ideas what i might be doing wrong?
I have tried netstat -an and i see :
TCP 127.0.0.1:4464 127.0.0.1:3306 Established
Upvotes: 0
Views: 11654
Reputation: 1
It is simple .. you need .jar file called mysql-connector-java-5.1.16-bin.jar ,,, download it and add it to your libs ...
good luck !!!
Upvotes: 0
Reputation: 2782
Try the followings:
If you want to ensure the username and password , you have to query the user table in mysql table again to need another mysql admin account to query.
Upvotes: 0
Reputation: 2987
i think you did not start the MySql server in your PC.before running your application
Upvotes: 0
Reputation: 2591
Do you sure that it is mysql running on port 3306 and that it's version is supported by your connector/j?
Upvotes: 0