JDBC/MySQL problem

Associate
Joined
30 Jun 2003
Posts
2,237
Location
Sussex
I'm writing some code with deals with databases, the connection to my oracle works okay but when trying to connect to a mysql, I get a strange error:

16:42:30: Creating new connection with url: jdbc:mysql://localhost:3306/db
16:42:32: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1

This is pretty much nigh-on impossible to google so I wonder if anyone has any ideas?
 
Have you tried supplying a username and password if the DB has one?

Code:
jdbc:mysql://localhost:3306/test?user=yourusername&password=yourpassword

for instance

Code:
jdbc:mysql://localhost/db?user=root

(assuming root has no password)

You also don't need to specify the port if you are running default. Username and Password left out of the connection string default to "" iirc.
 
Last edited:
Your connection code should look something like:

Code:
               String userName = "testuser";
               String password = "testpass";
               String url = "jdbc:mysql://localhost/test";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, password);

Is that what you have?
 
Your connection code should look something like:

Code:
               String userName = "testuser";
               String password = "testpass";
               String url = "jdbc:mysql://localhost/test";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, password);

Is that what you have?

Yep, that's pretty much it. I guess this is just a weird transient error :(
 
Back
Top Bottom