File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Connect to Oracle via JDBC using JSP.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connect to Oracle via JDBC using JSP.." Watch "Connect to Oracle via JDBC using JSP.." New topic
Author

Connect to Oracle via JDBC using JSP..

Gulab Singh
Greenhorn

Joined: Aug 09, 2001
Posts: 8
Can someone please provide a sample JSP code for connecting to a Oracle 8i database using JDBC.
I am using tomcat server
Gulab
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

I can write an application and bill you for that....
or you could refer to the tutorials on the Sun website
and save $$$.
http://java.sun.com/docs/books/tutorial/jdbc/index.html
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Jayanthimeena
Greenhorn

Joined: Jul 24, 2001
Posts: 17
Hai
this might help u.
<%@ page import="java.sql.*" %>
<%! Connection con;Statement stmt;ResultSet rs,rsMaterial;String state,Fadd;%>
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc racle:thin:scott/tiger@ipaddresswhere oracle is installed:1521:cle8i");
stmt = con.createStatement();
Bye
Jayanthi
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
I have a comment though on all this,
It's better to right your database connection statements and all in a bean and just use the useBean directive in jsp and call the connect method from there .. its alot more tidier that actually writing the code raw in the jsp. It beats the basic reason why we have jsp, to separate the presentation logic from the business logic.
C ya

------------------
KaReEm


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
Dave Soto
Ranch Hand

Joined: Sep 15, 2001
Posts: 55
Well, how about EJB for that matter? He's obviously just beginning with the whole J2EE thing, so he probably needs to take it one step at a time...
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
I'm having trouble too.
I posted this doubt in the JDBC forum but there's no answer yet. Perhaps you could tell me whats wrong with this line of code as it produces SQLExceptions (its the line 24 mentioned in the errors below.)

notes:
The Driver manager and class path are fine.
The user and password are "DEMO"
The database is called "MYDB"
The errors I get are:
Exception in thread "main" java.sql.SQLException: Excepci�n Io: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:323)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:263)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at driver_ver.main(driver_ver.java:24)

[This message has been edited by Terence Doyle (edited September 23, 2001).]


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Dave Soto
Ranch Hand

Joined: Sep 15, 2001
Posts: 55
First, make sure you are loading the driver, like this:

Then, you can try this syntax for making a connection instead:

Third, and most important. That error you are getting can also occur if Oracle is not running, or if the TNSListener is not running.
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Thanks,
Yes I suspect my oracle isnt doing its bit. I just downloaded it ( yes I know 277MB is a lot but luckily I have ADSL ) and installed it to be able to stick it on my CV
I'll have to get into the nitty gritty next week. For the moment I'm cramming for my Java Cert exam this Friday.....

Terry
 
wood burning stoves
 
subject: Connect to Oracle via JDBC using JSP..
 
Similar Threads
Shop Management System In JAVA
[JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
connection url
how to use data of type XMLTYPE in database in java
scrollable resultset