B14speedfreak
Technical User
- Mar 23, 2006
- 182
Hi all,
I am trying to learn about how to connect to databases with java using JDBC. Anyhow I have got hold of the connector from mysql, and have produced a small class using the documentation - just connects.
I am using MYSQL 5, Netbeans 3.6, JDK 1.4.2_04, JConnector 5.0.4.
I have included the jar file for jdbc driver in the $JAVA_HOME/lib folder, as well as including the location in the class path and path enviromental OS variables.
Anyhow using netbeans 3.6 I have been able to connect to the database, by defining it under the runtime tab on the left hand frame of the GUI. I can select tables and even execute sql and get results from the database. When I install the driver, the driver is defined as org.gjt.mm.mysql.Driver, under the MYSQL documentation they think that I should be using com.mysql.jdbc.Driver.
This is my script:
package music_connect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect {
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
}catch (Exception ex){
}try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/music?user=root&password=126120");
System.out.println("Connected");
conn.close();
System.out.println("connection closed");
}catch (SQLException exer){
System.out.println("SQLException: " + exer.getMessage());
System.out.println("SQLState: " + exer.getSQLState());
System.out.println("VendorError: " + exer.getErrorCode());
}
}
}
*****************////// results when executed////////////
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
Has anyone got any ideas how I can resolve this?
Thanks,
B14... aka... Marky Mark... the frozen monkey in the server room...
I am trying to learn about how to connect to databases with java using JDBC. Anyhow I have got hold of the connector from mysql, and have produced a small class using the documentation - just connects.
I am using MYSQL 5, Netbeans 3.6, JDK 1.4.2_04, JConnector 5.0.4.
I have included the jar file for jdbc driver in the $JAVA_HOME/lib folder, as well as including the location in the class path and path enviromental OS variables.
Anyhow using netbeans 3.6 I have been able to connect to the database, by defining it under the runtime tab on the left hand frame of the GUI. I can select tables and even execute sql and get results from the database. When I install the driver, the driver is defined as org.gjt.mm.mysql.Driver, under the MYSQL documentation they think that I should be using com.mysql.jdbc.Driver.
This is my script:
package music_connect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect {
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
}catch (Exception ex){
}try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/music?user=root&password=126120");
System.out.println("Connected");
conn.close();
System.out.println("connection closed");
}catch (SQLException exer){
System.out.println("SQLException: " + exer.getMessage());
System.out.println("SQLState: " + exer.getSQLState());
System.out.println("VendorError: " + exer.getErrorCode());
}
}
}
*****************////// results when executed////////////
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
Has anyone got any ideas how I can resolve this?
Thanks,
B14... aka... Marky Mark... the frozen monkey in the server room...