• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running sql in jsp

 
Micahel Kang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

Thanks,
Prabs
 
Rohit Suman
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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 {
DriverManager.registerDriver((Driver)Class.forName(driver).newInstance());
conn = DriverManager.getConnection(dburl,user,pwd);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from tab");
while (rset.next())
{
//fetch the data and display what you want.
}
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try{stmt.close();conn.close();
}catch(Exception e){e.printStackTrace();}
%>
}
don't forget put the classes12.jar in the lib directory
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PJ
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
 
Micahel Kang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Michael.
[ September 12, 2006: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic