File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes running sql in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "running sql in jsp" Watch "running sql in jsp" New topic

running sql in jsp

Micahel Kang

Joined: Jan 11, 2006
Posts: 6
I want to execute some oracle sql statements in my jsp page.
Could you please tell me how to establish a connection with the Oracle database.

Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
<%@ page import="java.sql.*"%>
String driver="oracle.jdbc.driver.OracleDriver";
String dburl="jdbcracle:thin:@localhost:1521radata";
String user="scott";
String pwd="tiger";
Connection conn=null;
try {
conn = DriverManager.getConnection(dburl,user,pwd);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from tab");
while (
//fetch the data and display what you want.
catch (Exception e) {
}catch(Exception e){e.printStackTrace();}
don't forget put the classes12.jar in the lib directory
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Welcome to JavaRanch!

We're pleased to have you here with us in the JSP forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Micahel Kang

Joined: Jan 11, 2006
Posts: 6
Thanks a lot for the reply.

I have a problem though.
I have installed Tomcat and have been running an application without any problem. But when I start this simple application it says resource not found.
The path of the jsp page is C:\Tomcat 5.0\webapps\jspbook\ch1\

The error message is
HTTP Status 404 - /jspbook/ch1/first.jsp


type Status report

message /jspbook/ch1/first.jsp

description The requested resource (/jspbook/ch1/first.jsp) is not available.

Could you please explain whatz happening here.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Thanks, Michael.
[ September 12, 2006: Message edited by: Ben Souther ]
I agree. Here's the link:
subject: running sql in jsp
It's not a secret anymore!