i am using Mysql workbench with java.i have installed JDBC driver from ubantu software center.but connection can not be done using "jdbc:mysql://127.0.0.1:3306/test"
.
Is there any class path required to be set or anything else is going wrong?
-
1MySQL workbench has nothing to do with a JDBC connection. It is just a GUI. – Tiny Feb 04 '14 at 11:50
-
possible duplicate of [Java connectivity with MySQL](http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql) – iCurious Feb 04 '14 at 12:15
-
I think they are talking about the MySQL Workbench GUI product, not making a Java jdbc connection. If that is correct, you need to make sure that your MySQL service is started, that it is listening on port 3306 and that MySQL has a database named 'test'. All of which SHOULD be there depending on how you setup MySQL. – mikemil Feb 04 '14 at 17:33
4 Answers
I am using MySQL Workbench with Java.
No you aren't. You are using MySQL Workbench, and you are using Java, but you aren't using one 'with' the other in any sense.
MySQL Workbench is a client. JDBC is another client. A client cannot connect to a client.
MySQL Workbench is not a JDBC client. A non-JDBC client cannot use a JDBC connection string to connect to a MySQL database.
In short, your question doesn't make sense.

- 305,947
- 44
- 307
- 483
You have to follow following steps in a sequence to make connection with MySql Database.
1) installed MySQL on your system. 2) download MySQL JDBC driver jar to add in project library. 3) create database and tables using command line or using workbench. 4) now use in your code to make connection :
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/test", "username", "password");
statement = connect.createStatement();
5) now perform your queries using Statement to update or fetch the data. 6) in last close the connection.

- 164
- 6
-
i hv done this .but another error is there HTTP Status 500 - Internal Server Error type Exception report messageInternal Server Error descriptionThe server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.NullPointerException root cause java.lang.NullPointerException note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs. GlassFish Server Open Source Edition 4.0 – jigisha Feb 04 '14 at 12:24
-
See the full stack trace to find where null pointer comes in code.you must be found if you will try it or post your full stack trace here to help you. – Balram Maurya Feb 05 '14 at 13:19
use this :
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "username", "password");
you forget to add Class.forname
Thanks..

- 1,854
- 3
- 21
- 43
-
Unnecessary since 2007, and doesn't identify the real problem here. – user207421 Jul 29 '17 at 12:27
Try to copy mysql-connector jar file to C:\Program Files(x86)\Java\jre\lib\ext then copy this pass to ClassPath in environment variables

- 1
- 1