This content has been marked as final. Show 13 replies
Connection conn = DriverManager.getConnection(add '?' at the end of url string, so your url become like this
Message was edited by:
Classpath, classpath, classpath.
Since you are using netbeans, ensure that the driver jarfile is included as one of the libraries for the project.
Edit: or if through your own code means from the command line, then ensure that the jarfile is listed under the -cp option.
no that didnt fix it, where am i supposed to put the connector/j driver at? what specific folder for windows? i mean i just have it on my desktop, but i thought netbeans setup the classpath to read it... but maybe it didnt, and i dont want a classpath going to a random folder on my desktop.
but then why could i access the db through the 'runetime' tab in netbeans?
You need to add it to the project as a library. It doesn't matter where you have it, as long as it is configured in the project.
well its nice that ya'll are helping me out, but how do i add it as a library?
okay im an idiot, i figured out how to add the libary, and set the classpath for the library, but it still didnt fix the error, i recompiled and ran again, and i still get the same error.
okay, after more tinkering i got it right, but now i get this huge ass long error...
init: deps-module-jar: deps-ear-jar: deps-jar: compile-single: run-main: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.ConnectException MESSAGE: Connection refused: connect STACKTRACE: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at java.net.Socket.<init>(Socket.java:366) at java.net.Socket.<init>(Socket.java:208) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:173) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:267) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739) at com.mysql.jdbc.Connection.<init>(Connection.java:1553) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at mysqlTest.NewClass.main(NewClass.java:10) ** END NESTED EXCEPTION ** Last packet sent to the server was 16 ms ago. BUILD SUCCESSFUL (total time: 3 seconds)
Stupid question, but did you remove the "?" from the URL that p_epi suggested you add. If you did not remove it, then remove it now. That is only needed if you are passing the user and password as a part of the URL, which you are not.
yeah i just removed it and tried again, same error
A few more stupid questions, but they need to be asked.
1. Is the DB currently running?
2. Is it using port 3306 (I assume it is since that is the default)?
3. In the configuration (the mysql.users table) is there an entry "root@localhost" or "root@%" or "root@<localip/hostname>"?
If the entry is "root@<localip/hostname>" exists, then change the connection url from "localhost" to the actual ip.
If none of the above is present, then add the "root@localhost".
If the above suggestion does not work, and the "root@<localip/hostname>" entry does not exist, add it and follow the first suggesstion.
The last suggesstion above is because I am not sure if the "root@localhost" option only allows access through the "sock" file, or if it also allows TCP access.
but when i do it through my own code... ummm... could you post your code?
He says in his follow up thread
that he has it working, but does not say what change he had to make.
It all had to do with classpath and then (probably) connection parameters (username, password, mysql config).
you need to have the jar file in your classpath which has com.mysql.jdbc package and a Driver class within tht package