Reputation: 7507
I've been trying for a while to connect to my database, and I am pretty close now I think.
But com.mysql.jdbc.Driver
refuses to load.
Here's my code:
import java.sql.*;
import com.apple.eawt.*;
import com.mysql.jdbc.Driver;
public class MySQL {
public MySQL() {
Connection conn = null;
try
{
String userName = "my_username";
String password = "*******";
String url = "jdbc:mysql://korilu.nl/phpMyAdmin/";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (SQLException ex)
{
System.err.println ("Cannot connect to database server (SQLException)");
System.out.println(ex.getMessage());
}
catch (ClassNotFoundException ex) {
System.err.println ("Cannot connect to database server (ClassNotFoundException)");
System.out.println(ex.getMessage());
}
catch (InstantiationException ex) {
System.err.println ("Cannot connect to database server (InstantiationException)");
System.out.println(ex.getMessage());
}
catch (IllegalAccessException ex) {
System.err.println ("Cannot connect to database server (IllegalAccesException)");
System.out.println(ex.getMessage());
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
public static void main(String args[]) {
new MySQL();
}
}
Currently it says: package com.mysql.jdbc
does not exist, although XCode autocompletes the import
line above.
I think I messed up with adding the package to my project, because I did not know how.
I just ctrl+clicked my target and selected Add to target...
and added the com folder with the .java files I downloaded.
I think that the compiler doesn't recognize it as a package but I don't know how to make it a package.
P.S.
I'm not quite sure about that URL, but that's not the problem for now (but I won't mind someone telling me where antagonist stores their databases).
Upvotes: 1
Views: 14896
Reputation: 112
Just add this library file in your libraries if you haven't yet.
Upvotes: 1
Reputation: 3027
I am not sure how Xcode handles this as I've not used it for Java development, however the usual cause of this error is the MySQL jdbc (connector) jar file not being on the classpath. Can you show us the command Xcode is using to launch the jvm?
Upvotes: 1