JDBC Connector installation
Posted by: Henry Chang
Date: April 18, 2005 01:09AM

Hi all,

I was unable to install the connector to connect to MySQL server. I have followed the instructions in the documentation, add the entries in the CLASSPATH, but when I run the following code, it displays the error:

Exceptions Caught!
SQLException: No suitable driver
SQLState: 08001
VendorError: 0

/*
* Main.java
*
* Created on April 17, 2005, 2:43 PM
*/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;

/**
*
* @author henrychang
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {System.out.println("Exceptions Caught!");}

String url = "jdbc:mysql://localhost:3306/weblibrary?user=root&password=abc";
try {
conn = DriverManager.getConnection(url);
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}

try {
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT name FROM books");
} catch (SQLException sqlEx) {}
finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx) {}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {}
stmt = null;
}
}
}
}

Options: ReplyQuote


Subject
Written By
Posted
JDBC Connector installation
April 18, 2005 01:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.