Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to JSP; how to connect to DB?

Status
Not open for further replies.

itbnorris

MIS
May 12, 2003
45
US
I'm new to JSP. Most of what I've done is Oracle PL/SQL or in ASP.

We recently set up an Oracle9i application server. Since I'm familiar with ASP, I figure JSP can't be too far of a stretch... and I can use it on this app server.

One thing I haven't been able to get to work is this: How do you connect to an oracle9i database from a JSP? (code example would be helpful) Every tutorial on the web I've looked at ends up being a mass of errors.

Also, can anyone recommend a good JSP book? Particularly JSP on Oracle9i App Server.

Thanks in advance.
 
Hi,

I am not sure about the Oracle9i App Server. Below is the code that you use to connect to the Oracle DB using JSP + any Servlet Container.

Just make sure you have classes12.jar file in your <<YourWebApp>>/WEB-INF/lib folder. You can find that in ORACLE_HOME dir and it would be in .zip rename it to .jar file and copy it into the lib folder.

Below is the code. There is a better of doing this.



<%@ page import=&quot;java.sql.DriverManager,
java.sql.Connection,
java.sql.ResultSet,
java.sql.Statement&quot;%>
<%

Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);
Connection conn = DriverManager.getConnection(&quot;jdbc:eek:racle:thin:mad:IPADDRESS:1521:DBNAME&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;);

Statement stmt = conn.createStatement();
String sqlString = &quot;SELECT * FROM TEMPTABLE &quot;;
ResultSet rs = stmt.executeQuery(sqlString);
while(rs.next()){
out.println(rs.getLong(1));
out.println(rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
%>

the code IPADDRESS >> YOUR DB IPADDRESS
DBNAME >> DB you want to connect
USERNAME >> DB USER NAME
PASSWORD >> DB PASSWORD

Cheers,
-Venu
 
I've found classes12.zip, but I have no idea where to put it. We have an oracle9i AS r2 portal application that we are working on. Portal is somewhat limited because of its wizards, so I figured we could get around some of our problems by using JSP pages in portal.

To do this in portal, you just &quot;create a new page&quot;, specify it as a JSP page, then upload your JSP source file.

I searched for folders like WEB-INF\LIB and it returned dozens of folders.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top