aspose file tools*
The moose likes JDBC and the fly likes database connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "database connectivity" Watch "database connectivity" New topic
Author

database connectivity

dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
hi all
what are the steps for connecting my java class to a oracle database using type 4 driver

Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Dipayan,

Check out Establishing Connection
dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
hi Balu

thanks a lot for the help i tried establishing a connection to my oracle 10g xe database

using the code:

import java.sql.*;

class Connn
{
public void get connection()
{
try{
Class.forName("oracle.jdbc.OracleDriver");
out.println("the driver has been loaded");
Connection con=DriverManager.getConnection("jdbcracle:thin:@acer:1521:xe","system","sys");
out.println("the connection has been established");
Statement stmt=con.createStatement();
int i=stmt.executeUpdate("insert into login values('"+s+"','"+s1+"')");
if(i==1)
{
out.println("data has been inserted into the database");
}
else
{
out.println("data could'nt be inserted into the database");
}
out.close();

}
catch(SQLException e)
{
out.println(e.getMessage());
}
catch(ClassNotFoundException f)
{
out.println(f);
}
}
}




but i am getting the following error

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

what went wrong ? i have created the required tables
dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
sorry a line got skipped form the above posted code

here s and s1 are two strings
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
How are you adding the JDBC driver's jar file to the classpath?


Ping & DNS - my free Android networking tools app
dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
i have set the following classpath

CLASSPATH=.;C:\oracle\ora101\jdbc\lib\ojdbc14.jar;

do i need to include more jar files in my classpath
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


i have set the following classpath

CLASSPATH=.;C:\oracle\ora101\jdbc\lib\ojdbc14.jar;

do i need to include more jar files in my classpath


That should work then. Check if the jar exists there and add it at the entry at the beginning of the CLASSPATH.
CLASSPATH=C:\oracle\ora101\jdbc\lib\ojdbc14.jar;.;

type CLASSPATH in the cmd to check if your classpath is set right

Can you tell us how do you set this classpath and run the application ? Using any IDE ?
dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
hi balu
the jar file ojdbc14 exsists i have also checked the classpath but the problelm still persists . i am using myeclipse 6 workbench
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: database connectivity