PDA

View Full Version : MySQL and Java



adriana_l_2000
07-06-2006, 07:17 PM
Hello,
I would like to access MySQL DB using java, but I don't know how. I found this:


import java.sql.*;
class prueba {
public static void main (String[] args) {
try {

// Step 1: Load the JDBC driver.
Class.forName("com.mysql.jdbc.Driver");

// Step 2: Establish the connection to the database.
//String url = "jdbc:msql://www.myserver.com:1114/contact_mgr";
String url = "jdbc:msql://linuxfire:3306/sismosprueba";
Connection conn = DriverManager.getConnection(url,"admsismos","rzambrano");

} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}

But it doesn't work. I think it is because of the driver, but I don't know which one I should use.
Thanks
Adriana

Twey
07-06-2006, 08:14 PM
You have to have the jdbc/mysql.jar file provided with MySQL in your CLASSPATH.