Asked By
anonymous
7060 points
N/A
Posted on - 09/18/2011
How do I connect with MySql using java? Could you give me the code with explanation? Thanks.
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Â
(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
Â
Â
Â
Â