How do I Connect with MySql Server using java?

Asked By 7060 points N/A Posted on -

How do I connect with MySql using java? Could you give me the code with explanation? Thanks.

Answered By 0 points N/A #80454

How do I Connect with MySql Server using java?


Here the Steps for ConnectorJ

Step 1: First Download connectorJ

Platform Independent (Architecture Independent), ZIP Archive

Step 2: Copy  ung mysql-connector-java-5.1.17-bin.jar then paste to Java Folder

Ex: (D:Program FilesJavajdk1.6.0_18jrelibext)

Step 3: Open environmental variables click new in system variables then

Variable Name: CLASSPATH
variable Value: .;D:Program FilesJavajdk1.6.0_18jrelibextmysql-connector-java-5.1.17-bin.jar <<<<< Path of your 


then click ok! then restart your pc

String driver="";
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "root", "12345");
st = con.createStatement();
ResultSet res = st.executeQuery
}catch(Exception error)
This is all code did you need to connect Java to mysql
i used that code for in my last project 😀 
The pictures below are the steps for Environmental Variables in your Path of ConnectorJ


Login/Register to Answer

Related Questions