Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

mckoi database driver & ClassLoader

843854May 10 2002 — edited May 15 2002
i believe i have a properly working custom classloader for the driver,
but now i'm getting a problem with of this chunk of code.
at the end, the sql exception gets thrown with the message being:

"Unable to make a connection to the database.
The reason: No suitable driver"
i tested this application by running:
java -cp ../../mckoidb.jar:. SimpleApplicationDemo and everything is working fine. the code i did chage has comments about it.
any help will be greatly appreciated :>

//----------------------------------------------------------
import java.sql.*;
import java.net.*;
public class SimpleApplicationDemo {
/**
* The demonstation 'main' method.
*/
public static void main(String[] args) {
System.out.println();
// Register the Mckoi JDBC Driver
try {
// ---------------- start modified code --------------------------
URL[] urlsToLoadFrom = new URL[]{new URL("file:../../mckoidb.jar")};
URLClassLoader loader = new URLClassLoader(urlsToLoadFrom);
Class JDBCDriver = Class.forName("com.mckoi.JDBCDriver", true, loader);
// ---------------- end modified code --------------------------

// below is the orginal code - when uncommented works with:
// java -cp ../../mckoidb.jar:. SimpleApplicationDemo
//Class.forName("com.mckoi.JDBCDriver").newInstance();
}
catch (Exception e) {
System.out.println(
"Unable to register the JDBC Driver.\n" +
"Make sure the classpath is correct.\n" +
"For example on Win32; java -cp ../../mckoidb.jar;. SimpleApplicationDemo\n" +
"On Unix; java -cp ../../mckoidb.jar:. SimpleApplicationDemo");
return;
}
// This URL specifies we are connecting with a local database. The
// configuration file for the database is found at './ExampleDB.conf'
String url = "jdbc:mckoi:local://ExampleDB.conf";
// The username/password for the database. This is set when the database
// is created (see SimpleDatabaseCreateDemo).
String username = "user";
String password = "pass1212";
// Make a connection with the database.
Connection connection;
try {
connection = DriverManager.getConnection(url, username, password);
}
catch (SQLException e) {
System.out.println(
"Unable to make a connection to the database.\n" +
"The reason: " + e.getMessage());
return;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2002
Added on May 10 2002
3 comments
212 views