oracle a problem to me
hi ppl,
i have wrote the following code to access a oracle Table(Emp).
my dsn name is oracle
port no i have given is 389
and i am using thin driver.
i have included classes12.zip file in the classpath also.
still i am getting the "java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver " error.
how can i get rid of it.
expecting useful replies.
thank u pals.
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver ");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:389:oracle", "scott", "tiger");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from Emp");
if(rs.next())
{
out.println("connection established");
}
else{
out.println("connection not established");
}
}
catch(Exception e)
{
out.println(e);
}
%>
# 1
Put the driver in the classpath. http://java.sun.com/docs/books/tutorial/jdbc/
# 2
thank u but it didnt work.how can u remove the error.
# 3
i think u need to check class path settings. i have been using oracle10g with no problem. i m also using the thin driver. the below is the information::
driverClass = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@localhost:1521:xe"; (xe is SID, 1521 is port configured while installing)
further i m having one ojdbc14_g.jar file set in my class path which is there in oracleinstallationdirectory\app\oracle\product\10.2.0\server\jdbc\lib.
PS. if u r using any server like tomcat, then u need to put this file in classpath of tomcat in order to tomcat to use it.
i hope it helps.
# 4
> thank u but it didnt work.
> how can u remove the error.
Put the driver in the classpath. If you're still getting the error then you didn't do this - you just thought you did.
If you're using Tomcat, put the driver in the common/lib directory below the Tomcat installation directory.
And read the tutorial.
# 5
And remember that the things you put in Tomcat's common/lib directory, or your web application's WEB-INF/lib directory, must be jar files. If your driver is in something called "classes12.zip" then that isn't a jar file.The solution to that is trivial.
# 6
the classpath is:
classpath=%classpath%;C:\Program Files\Java\jdk1.6.0\bin;C:\oracle\ora92\jdbc\lib\classes111.jar;C:\oracle\ora92\jdbc\lib\classes12.jar;
the program is:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<%
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@9i_06:2030:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from emp";
ResultSet rs=stmt.executeQuery(sqlstmt);
if(rs.next())
out.println("executed");
else
out.println("not executed");
}
catch(Exception e)
{
out.println(e);
}
%>
i have put jar files in javahome/jre/lib
and tomcat/lib
and in path also
but i am not able to compile the program.
just suggest me something friends.
its really bugging me.still the same error"java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver "
plz help me friends
thanks in advance
# 7
1. The classpath environment is not "the classpath".2. Even if it were you don't put JAR files into it anyway.3. Just do what we told you to do instead of arguing.
# 8
how can i put the driver in the classpath i m new to oracle thats why i am not able to understand.plz dont mind and give some example.thanku
# 9
What application server are you using?
# 10
As dcminter said, put ojdbc14.jar or classes12.jar into Tomcat/common/lib/, then remove the deployed app and redeploy it.BTH, it's a very bad idea to do DB access in a JSP. Use a servlet instead. JSPs should be used to display data/form only...hth
# 11
classpath=.;%classpath%;classes.zipyour driver is in classpath
# 12
The classpath environment variable is not "the classpath".
# 13
ok
let me completely explain the environment.
i am using java 1.6
tomcat 5.5.17
i have placed all the jar files from
oracle/ora92/jdbc/lib/
to
tomcat5.5/common/lib
i have created user dsn with the name orcl
i wrote the program as :
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<%
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@9i_06:2030:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from emp";
ResultSet rs=stmt.executeQuery(sqlstmt);
if(rs.next())
out.println("executed");
else
out.println("not executed");
}
catch(Exception e)
{
out.println(e);
}
%>
classpath is:
C:\Program Files\Java\jdk1.6.0\bin;C:\oracle\ora92\jdbc\lib\;
suggest me the changes plz
# 14
after making some modification suggested by you people i got another errorjava.sql.SQLException: Io exception: Connection reset how can i eliminate it.thanku
# 15
and the latest error isjava.sql.SQLException: Io exception: The Network Adapter could not establish the connection how can i remove it
# 16
plz check our port no ,usernsme,password and you dont need importing oracle.jdbc.driver because u have imported java.sql package and u dont need to set classpath because webcontiners internaly have path to ojdbc14.jar and u r telling that my user name is dsn
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","username","password");
Statement stmt=con.createStatement();
String sqlstmt="select * from emp";
ResultSet rs=stmt.executeQuery(sqlstmt);
if(rs.next())
out.println("executed");
else
out.println("not executed");
}
catch(Exception e)
{
out.println(e);
}
%>
# 17
root+
+WEB-INF+
-classes
--lib
--web.xml
-one.jsp
url is http://localhost:8080:one.jsp
hi this is dirctory structure
lib directory empty
classes directory empty
web.xml is
<web-app>
</web-app>
this is enough
no cofiguration is needed
# 18
> root+
>+WEB-INF+
>
> classes
>
> -lib
>
> -web.xml
>
> one.jsp
> url is http://localhost:8080:one.jsp
>
>
> hi this is dirctory structure
>
> lib directory empty
> classes directory empty
> web.xml is
> <web-app>
> </web-app>
> this is enough
> no cofiguration is needed
>
your total root folder should be in c:\jakartha..1.6\webapp directory
# 19
I'd ignore eswar if I were you - he doesn't appear to have the faintest idea what he's talking about.Either your Oracle instance is not running, or your firewall is preventing Java from establishing connections.
# 20
hi dcminter i am not able to understand you what you have takilng
# 21
Hi u forget about the classpath..put the mysql/oracle connector jar file inside/java/jre/lib/extand try..i hope this will work.
# 22
> hi dcminter i am not able to understand you> what you have takilngNor did you understand what the original poster was talking about. So you're an idiot to try and answer.
# 23
> Hi
> u forget about the classpath..
> ut the mysql/oracle connector jar file inside
> /java/jre/lib/extand try..
> i hope this will work.
It's no longer a classpath problem. So you're an idiot.
That's the wrong place to put ordinary JAR files. So you're an incompetent too.
# 24
>>>>and the latest error is
>>>>java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
>>>>how can i remove it
Either network connection is down or database may not be up and running. So check the 2 and execute the program.
# 25
hey guys thanku for your repliesand helpnow ia m getting the errorconnection refusedits a new errori goti think i have some progress in my workbut get me the final resultthank u
# 26
please, post your final test code ?btw, you should only put ojdbc14.jar in tomcat5.5/common/lib/
# 27
There might be JDBC conflict, try with JDBC for oracle 9.2
Remove obsolete drivers
C:\oracle\ora92\jdbc\lib\classes111.jar ... for JRE 1.1
C:\oracle\ora92\jdbc\lib\classes12.jar ... for JRE 1.2/1.3
Add correct driver (JRE 1.4 or later)
C:\oracle\ora92\jdbc\lib\ojdbc14.jar; (or ojdbc14.zip)
# 28
I meant, remove obsolete drivers from classpath, and add correct driver (JRE 1.4 or later) to classpath
# 29
hello ppl,
host : 9i_06
sid : orcl
port no : 1521
and the error is
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
i have searched through internet and i found that the url is wrong
below is my program for accessing database.
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<%
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@9i_06:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
if(rs.next())
{
out.println("executed");
}
else
{
out.println("not executed");
}
}
catch(Exception e)
{
out.println(e);
}
%>
can u help me.
# 30
ya i my adminstrator has changed the sid from orcl to database.thats the problemthanking you for all ur repliesnow i am able to access databasereally thanking u
# 31
sorry for this... i didnt check the second page!My apologies!Message was edited by: G_Abubakr