Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
JDBC driver in Xcode?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JDBC driver in Xcode?



I'm struggling with making a simple Java database connection using Xcode.  Here's my code (database details omitted):

import java.sql.*;

public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "";
String dbName = "";
String driver = "com.mysql.jdbc.Driver";
String userName = "";
String password = "";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Each time I run this code, I get the following result in Console:

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at MysqlConnect.main(MysqlConnect.java:18)



My JDBC driver file is called mysql-connector-java-5.1.7-bin.jar, and I've placed it into my Library/Java/Extensions folder (at root, not user directory).  I've tried various CLASSPATH designations, putting the .jar file into various folders within my project, and nothing seems to work.  I've done a bunch of web searching and have tried all sorts of suggestions, but nothing seems to work.  I've yet to find a good example of how this setup is accomplished.

Oh, one other question: if I want to connect to a shared hosting database, what should my URL look like?  Most examples I've seen follow a format like:

jdbc:mysql:<dbName>[propertyList]

... but I didn't know if I should be preceding a remote IP with any prefixes (e.g., "jdbc:mysql:"), or just use the URL by which I normally access my database via PHP and such.

Any guidance is appreciated!
Dave



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.