How do I Connect with MySql Server using java?

Asked By 7060 points N/A Posted on -
qa-featured

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

SHARE
Answered By 0 points N/A #80454

How do I Connect with MySql Server using java?

qa-featured

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 

(mysql-connector-java-5.1.17-bin.jar)

then click ok! then restart your pc

try{
String driver="org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();
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