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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC Connection Error

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
I am trying to run the JDBC Connection on a Local Database. The SID = TST9. The user who has access to the SID is user. The program compiles fine. But for some reason it would not run. When I run I get an exception. Could someone please let me know what could be the problem.

Code:
//  Establish a connection to a Oracle database using JDBC.
import java.sql.*;

class JdbcTest1 {

    public static void main (String[] args) {
        try {

            // Step 1: Load the JDBC driver.
            Class.forName("oracle.jdbc.driver.OracleDriver");

            // Step 2: Establish the connection to the database.
            String url = "jdbc:oracle:thin:@//localhost:1521/tst9";
            Connection conn = DriverManager.getConnection(url,"user","password");

        } catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());
        }
    }
}

Code:
C:\winpack\samples>java JdbcTest1
Exception in thread "main" java.lang.NoClassDefFoundError: JdbcTest1
 
Yes, the compiled class is not on the classpath when you run it.

There is probably something about classpaths in the FAQ for this forum. It is essential to understand the classpath concept if you're intending to take Java seriously.


Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top