• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and JDBC  RSS feed

 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could somebody please post an example utilizing JSP for a query of a database? I am trying to show how one would use just JSP for this purpose.
Thanks,
Kevin
 
sky0704
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Here is a simple example of query in JSP.
(using oracle database and need BONUS table--anything can do)
<%@ page language="java" import="java.sql.*" contentType="text/html" %>

<%
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection Conn =
DriverManager.getConnection("jdbcracle:thin:@127.0.0.1:1521:sky0704","SCOTT","TIGER");

Statement stmt = Conn.createStatement();

ResultSet rs = stmt.executeQuery("select * from BONUS");

if (rs==null)
{
out.println("Nothing here");
}
else {
out.println("Something here");
}

stmt.close();
Conn.close();
%>

Good Luck!!
------------------

[This message has been edited by sky0704 (edited July 17, 2001).]
[This message has been edited by sky0704 (edited July 17, 2001).]
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posibly the best example I can think of is the examples that come ith the Jakarta DB Tag Lib at http://jakarta.apache.org/taglibs/doc/dbtags-doc/intro.html

------------------
Hope This Helps
Carl Trusiak, SCJP2
 
Rehan Malik
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sky gave a good example of a JSP/JDBC page.
If you wanted to build upon it, you could make a JavaBean that handles the connection to the database as well as also returning data in an easy to manage way.
Connection Pooling is also a concept to look into which would be more efficient at making database connections and less resource intensive.
 
krupa devi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rehan,
Can you provide sample code for making a java bean to handle all the connection to the database as well as also returning data so that I can show that in the form of a html table.
Thanks in advance,
Krupa
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!