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 {
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
System.out.println("Disconnected from database");
} catch (Exception e) {

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

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at MysqlConnect.main(

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:


... 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!

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.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.