Hi Pradeep Roy,
U r making the database connection in ur setSql()
function and that function is not called any where.
Either u make the database connection in the
constructor of the bean and use that connection later
in the function.
Or call the setSql function in the jsp page like
<% dbConnect.setSQL(query); %>
before ur call to get the resultSet.
Vivek Ojha
--- Pradeep Roy <[EMAIL PROTECTED]> wrote:
> Hi All
>
> I am enclosing a complete code for database
> accessing. It would help
> beginners to know how to access the database from
> JSP.
> But I don't want the JSP to access the database. I
> want Beans to Access the
> database and send ResultSet accross to JSP. It is
> not working whenever I am
> trying to use the Beans to access it.
>
> Any other suggestion with details will be highly
> appreciated.
>
> Thanks & Regards
> Pradeep
>
> Could anyone suggest me what is wrong in my Bean
> which is expected to
> return a result set in the JSP file.
>
> package dbAccess;
>
> import java.util.*;
> import java.sql.*;
> import java.lang.*;
> import java.io.*;
>
> public class jspDbAccess {
>
> Vector names;
> Vector data;
> String firmcode;
> String workid;
> String job;
> String costcode;
> ResultSet resultSet=null;
>
>
> //
> public jspDbAccess()
> {
> ;
> }
>
>
> //
> public void setFirmcode(String firm)
> {
> if (firm != null )
> {
> firmcode=firm;
> }
> }
>
> //
> public void setWorkid(String id)
> {
> if (id != null )
> {
> workid=id;
> }
> }
>
> //
> public void setJob(String Jobname)
> {
> if (Jobname != null )
> {
> job=Jobname;
> }
> }
>
> //
> public void setCostcode(String code)
> {
> if (code != null )
> {
> costcode=code;
> }
> }
>
>
> //
> public void setSql(String sqlStr)
> {
> Connection connect=null;
> Statement statement=null;
>
>
> String
> driverName="com.ibm.as400.access.AS400JDBCDriver";
> String url="jdbc:as400://saturn" ;
> String user="xxxx";
> String passwd="xxxx";
>
> Connection connection=null;
>
> // Data to connect to database
>
> try
> {
> //loading the driver
> Class.forName(driverName);
> connection =
> DriverManager.getConnection(url, user, passwd);
>
> }
> // Error if fail to load the driver
> catch (Exception exp)
> {
> connection=null;
> System.out.println("Error occured at
> loading the Driver: "
> +exp);
> }
>
>
> try
> {
> statement=connection.createStatement();
>
> resultSet=statement.executeQuery(sqlStr);
> }
> catch (Exception exp)
> {
> System.out.println("Error occured at
> loading the Driver: "
> +exp);
> }
>
> }
>
>
> public ResultSet getResultset()
> {
> return resultSet;
> }
>
>
> public void reset()
> {
>
> }
> }
>
>
> My JSP is as follows:
>
>
>
> <%@ page import="java.sql.*,java.io.*, java.lang.*,
> javax.servlet.
> *,javax.servlet.http.*" %>
>
> <jsp:useBean id="dbConnect"
> class="dbAccess.jspDbAccess" scope="session">
> <jsp:setProperty name="dbConnect" property="*" />
> </jsp:useBean>
>
> <html>
> <head> <titleEnquiry</title> </head>
> <body text="White"
> bgcolor="#000000"
> leftmargin=0
> topmargin=0
> marginwidth=0
> marginheight=0>
>
> <hr align="left" width=19% size=2 color="White">
>
> <table width="175" border="0" cellspacing="0"
> cellpadding="0">
>
> <tr>
> <td valign="TOP">
> <img align="middle" src="Logo_3.gif"
> width=149 height=75 border=0
> alt="Logo"></td>
> </tr>
>
> </table>
>
> <hr align="left" width=19% size=2 color="White">
>
> <img align="middle" src="enquiry.gif" width=780
> height=16 border=0 alt
> ="Jobpac Logo">
>
> <% if ((request.getParameter( "Workid" ) !=
> null) &&
> (request.getParameter( "Job" ) != null) &&
> (request.getParameter( "Costcode" ) !=
> null) &&
> (request.getParameter( "Sql" ) != null)) {
> %>
>
> <%
> String firm = request.getParameter( "Workid"
> );
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail � Free email you can access from anywhere!
http://mail.yahoo.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets