• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

running sql in jsp

 
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
 
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="jdbc:oracle:thin:@localhost:1521:oradata";
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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 VI Editor Redhat
  • 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
Boost this thread!