Forbinder til exstern database i java
Kære eksperten.Jeg får et problem med at forbinde til min egen database
og ved simpelhen ikke hvorfor.
Håber nogle her kan hjælpe :D
Fejlen er:
Connection refused: No suitable driver found for
mydb4.surf-town.net.
min code:
public class ConnectToMyOwnDatabaseSuftTown {
private Connection con = null;
private Statement st = null;
private String login, passwd, url, driverClass;
public ConnectToMyOwnDatabaseSuftTown() {
login = "xxxxxxx";
passwd = "xxxxxxxx";
url = "mydb4.surf-town.net:3306";
this.driverClass = "sun.jdbc.odbc.JdbcOdbcDriver";
System.out.println("Connecting");
connect();
}
public final void connect() {
try {
Class.forName(driverClass);
con = DriverManager.getConnection(url, login, passwd);
st = con.createStatement();
} catch (java.lang.ClassNotFoundException ex) {
System.err.print("ClassNotFoundException: ");
System.err.println(ex.getMessage());
} catch (SQLException ex) {
System.err.print("Connection refused: ");
System.err.println(ex.getMessage());
close();
}
}
public void close() {
try {
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
}
public static void main(String[] args) {
ConnectToMyOwnDatabaseSuftTown c = new ConnectToMyOwnDatabaseSuftTown(); }
}