• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

running sql in jsp

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Michael.
[ September 12, 2006: Message edited by: Ben Souther ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic