do you have the drivers installed?
is it throwing an exception? if so what is it?
This is the code i use for a mysql connection:
Code:
package net.codecall.forums.general;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySqlConnect {
public static void main(String args[]) {
Connection con = null;
String dbname = "";
String dbuname = "";
String dbpassword = "";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///" + dbname, dbuname, dbpassword);
if(!con.isClosed()){
System.out.println("Successfully connected to " + dbname);
}
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null){
con.close();
}
} catch(SQLException e) {}
}
}
}
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum