Helpful Information
Home
Categories
Contact us
Category: MySQL and other databases
MySQL and Java
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
You have to have the jdbc/mysql.jar file provided with MySQL in your CLASSPATH.
privacy (GDPR)