#284 Can't connect to Oracle DB with DrJava

open
nobody
5
2012-02-08
2012-02-08
Chris
No

I am trying to do a simple connection to an Oracle database and I have moved the ojdbc6.jar file into the same directory as the program file, but it still will not work. Any suggestions?
Here is the code (it dies on the line that says DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
with the error message package oracle.jdbc does not exist):

import java.sql.*;

class SimpleJDBC
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@server:1521:ORCL",
"userid", "password");

// Create a Statement
Statement stmt = conn.createStatement ();

// Select the table names from the user_tables
ResultSet rset = stmt.executeQuery ("select TABLE_NAME from USER_TABLES");

// Iterate through the result and print out the table names
while (rset.next ())
System.out.println (rset.getString (1));
}
}

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks