Error trying to connect to oracle express using jdbc
447592Jun 4 2006 — edited Jun 6 2006Hi,
I'm tring to connect a java class with and oracle database. I'm using eclipse and oracle express. I get an error like:
Exception in thread "main" java.lang.NullPointerException
at JdbcTest.main(JdbcTest.java:29)
I don't know what is wrong. I would like to know the right place to put the jdbc driver for the application access. Do i need to create classpath. I did like an example but i just doesn't work. Here is the code i used:
import java.sql.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class JdbcTest {
public static void main (String args[]) throws SQLException
{
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@localhost:1521:MyApp");
ods.setUser("hr");
ods.setPassword("hr");
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT first_name FROM employees");
//Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
NOTE: The import sentence import oracle.jdbc.pool.OracleDataSource;
causes an error too. The error says that it can't be resolved.
Please, May anyone help me?
Thanks anyway.