Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect to Oracle via JDBC using JSP..

 
Gulab Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Jayanthimeena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic