Results 1 to 2 of 2
- 11-10-2010, 06:38 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
JDBC connection failed to oracle 10g can anyone help
iam trying to connect to oracle 10g using this code but iam unable to connect please help me
package jdbcstatements;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JDBCConnection {
public static void main(String[]args)
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection( url, "scott", "tiger");
System.out.println("connection created");
Statement db_statement = con.createStatement();
db_statement.executeUpdate
("create table employee { int id, char(50) name };");
con.commit();
ResultSet result = db_statement.executeQuery
("select * from employee");
while (result.next() )
{
// Use the getInt method to obtain emp. id
System.out.println ("ID : " + result.getInt("ID"));
// Use the getString method to obtain emp. name
System.out.println ("Name : " + result.getString("Name"));
System.out.println ();
}
} catch(Exception e){e.printStackTrace();}
}
}
the error iam getting ids
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at jdbcstatements.JDBCConnection.main(JDBCConnection. java:17)
- 11-11-2010, 08:58 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Your Oracle driver jar file is not on the runtime classpath.
How you run this will determine how it gets fixed.
As a note, code should be posted in code tags to retain formatting.
And do not eat exceptions. At the very least printStackTrace().
And finally you should close your resources (resultset, stetamenet, connection) in a finally block.
Similar Threads
-
JDBC with Netbeans/Oracle
By sehudson in forum Advanced JavaReplies: 1Last Post: 03-11-2010, 09:26 AM -
JDBC Oracle Connection
By Bean in forum New To JavaReplies: 13Last Post: 11-06-2009, 08:06 PM -
oracle JDBC java
By silia_motor in forum JDBCReplies: 4Last Post: 05-10-2009, 09:37 AM -
Jdbc Driver For Oracle
By Swamipsn in forum New To JavaReplies: 0Last Post: 08-14-2007, 04:31 AM -
Oracle and JDBC
By Eric in forum JDBCReplies: 3Last Post: 08-11-2007, 08:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks