File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database connectivity

 
dipayan chatterjee
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
what are the steps for connecting my java class to a oracle database using type 4 driver

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dipayan,

Check out Establishing Connection
 
dipayan chatterjee
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry a line got skipped form the above posted code

here s and s1 are two strings
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you adding the JDBC driver's jar file to the classpath?
 
dipayan chatterjee
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic