JDBC

Can you tell me what I'm possibly missing here... The database is on a remote server, and I'm trying to connect via my machine:

import java.sql.*;

import javax.swing.*;

/**

* @author administrator

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class connect {

public static void main(String[] args) {

Connection connection = null;

try {

// Load the JDBC driver

String driverName = "oracle.jdbc.driver.OracleDriver";

Class.forName(driverName);

// Create a connection to the database

String serverName = "000.000.000.000";

String portNumber = "0000";

String sid = "will";

String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;

String username = "uid";

String password = "passwd";

connection = DriverManager.getConnection(url, username, password);

} catch (ClassNotFoundException e) {

// Could not find the database driver

//JOptionPane.showMessageDialog(null, "Could not find the database driver");

System.out.println("Could not find the database driver");

} catch (SQLException e) {

// Could not connect to the database

JOptionPane.showMessageDialog(null, "Could not connect to the database");

}

}

}

What do I need on my machine.

1. Do I need to alter the TNS names?

2. Do I need to have the jave code (application) on the server in-order to execute? Or can I run it from my machine,as long as I have the correct servername,portnumber, sid, etc...

I'm running into my exception handler of "Could not find the database driver"...

[1797 byte] By [willshera] at [2007-11-27 11:58:01]
# 1

The driver is not in your classpath.

cotton.ma at 2007-7-29 19:17:16 > top of Java-index,Java Essentials,Java Programming...
# 2

You have to have the driver class in the classpath of your application. It is likely in a .jar file and you'll want to put it in the /META-INF/lib folder associated with your application. (This assumes that we're talking about a desktop app). Also, if you deploy your application when you create the .jar of the application make sure it includes the /META-INF folder.

PS.

puckstopper31a at 2007-7-29 19:17:16 > top of Java-index,Java Essentials,Java Programming...