Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help using Connector/J and JDBC

Status
Not open for further replies.

jeronimo42

Programmer
Dec 2, 2002
2
0
0
US
I'm having some troubles with the JDBC Connector/J for MySQL. The documentation says the driver I should use is "org.gjt.mm.mysql.Driver". I typed up a simple driver program and it gives me an exception after these lines of code.

String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();

How do I get this driver to work?
Also, what is the syntax of the URL for Connector/J? Do I have to locate an actual file? Thanks a bunch!

J. Ciolkosz
 
I actually have the driver portion working now. How do you make a connection to a specific file though?
 
This is how I used the connector - I'm pretty sure this is the right way to do it, though this is for a few releases back...

String MYSQL_HOST = "192.168.0.2",
MYSQL_DB = "mysqldb",
MYSQL_USER = "myuser",
MYSQL_PASSWD = "blah",
MYSQL_TABLE = "mysqltbl",
MYSQL_URL = "jdbc:mysql://" + MYSQL_HOST + "/" + MYSQL_DB;
Connection Conn = null;
Statement Stmt = null;
ResultSet RS = null;

try
{
org.gjt.mm.mysql.Driver dbDriver = new org.gjt.mm.mysql.Driver();
Conn = DriverManager.getConnection(MYSQL_URL,MYSQL_USER,MYSQL_PASSWD);
Stmt = Conn.createStatement();
RS = Stmt.executeQuery("SELECT * FROM " + MYSQL_TABLE + " WHERE userID = " + userID + " AND passwd = " + passWD);

//Do your SQL stuff here...

RS.close();
Stmt.close();
Conn.close();
} catch (Exception e)
{
System.out.println("Connection failed:" + e.getMessage());
} napa1m
hansen@ithsite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top