File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connect to Oracle via JDBC using JSP.." Watch "Connect to Oracle via JDBC using JSP.." New topic

Connect to Oracle via JDBC using JSP..

Gulab Singh

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
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 $$$.
- satya

Take a Minute, Donate an Hour, Change a Life

Joined: Jul 24, 2001
Posts: 17
this might help u.
<%@ page import="java.sql.*" %>
<%! Connection con;Statement stmt;ResultSet rs,rsMaterial;String state,Fadd;%>
con = DriverManager.getConnection("jdbc racle:thin:scott/tiger@ipaddresswhere oracle is installed:1521:cle8i");
stmt = con.createStatement();
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


<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
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.)

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(
at oracle.jdbc.dbaccess.DBError.throwSqlException(
at oracle.jdbc.dbaccess.DBError.throwSqlException(
at oracle.jdbc.driver.OracleConnection.<init>(
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(
at oracle.jdbc.driver.OracleDriver.connect(
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at driver_ver.main(

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

Raising Flares debut album 'Ignition' out now

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
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.....

I agree. Here's the link:
subject: Connect to Oracle via JDBC using JSP..