Database connectivity in JSP

Hi all,
i am new to JSP and first time trying this code.i am trying to make a connection with the database,there is some problem in SQL.it show me SQLException.
Here is code connec.jsp:
<%@ page import="java.sql.*" %>
<% String name = request.getParameter("name");
String age = request.getParameter("age");
%>
<%
Connection conn = null;
Statement stmt = null;
     PreparedStatement pstmt = null;
ResultSet rs = null;
     try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          conn = DriverManager.getConnection ("jdbc:odbc:unsoda_project","project_unsoda","project");
     }catch (Exception e) {
          out.println(e);
%>
<!-- To read values from the database -->
<TABLE>
<%
     try {
          stmt = conn.createStatement();
          rs = stmt.executeQuery("Select codes from code_filter where codes > 1020");
          while(rs.next()) {
%>
<TR><TD><!%rs.getInt()%></TD>
</TR>
<%
     }catch (Exception e) {
          out.println(e);
%>     
</TABLE>
%>
When i tried to see the output through web browser it show me Exception:
/*java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00913: too many values */
Now pls. tell me how do i do this connectivity and can diaplay the output of the query into the combo box.
Thank you,
sonika

which of your catch blocks is throwing the exception. From the looks of the message, the ODBC driver is having and argument with the oracle driver based on your query. It says it is wrong. You shouldn't get the error about parameters if your driver doesn't connect, so I don't think that's the problem, I think it is your query.

Similar Messages

  • When and How to close database connection in JSP?

    Hi there,
    I am using MySQL and JDBC 3.0, in my system, When and How to close database connection in JSP?
    Thanks in advance.
    Lonely Wolf
    <%@ page session="true" language="java" %>
    <jsp:include page="checkauthorization.jsp" />
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    <%--
    Execute query, with wildcard characters added to the
    parameter values used in the search criteria
    --%>
    <sql:query var="availablecomputerList" dataSource="jdbc/Bookingcomputer" scope="request">
    SELECT * FROM computer where status=0
    order by s_code
    </sql:query>
    <html>
    <head>
    <title>Search Result</title>
    </head>
    <body bgcolor="white">
    <center>
    <form action="checkin.jsp" method="post">
    <input type="submit" value="Back to Check-in Page">
    </form>
    <c:choose>
    <c:when test="${availablecomputerList.rowCount == 0}">
    Sorry, no available computer found.
    </c:when>
    <c:otherwise>
    The following available computers were found:
    <table border="1">
    <th>Computer</th>
    <th>Description</th>
    <th>Status</th>
    <c:forEach items="${availablecomputerList.rows}" var="row">
    <tr>
    <td><c:out value="${row.s_code}" /></td>
    <td><c:out value="${row.description}" /></td>
    <td><c:out value="${row.status}" /></td>
    </tr>
    </c:forEach>
    </table>
    </c:otherwise>
    </c:choose>
    </center>
    </body>
    </html>

    when should you close the connection? when you're done with it.
    how should you close the connection? like this: conn.close();
    that said, doing this in a JSP page is bad form and not recommended
    JSP's typically don't contain ANY business or data logic

  • How to establish a MYSQL Database connection in JSP page.

    Hi People,
    Tell me how to establish mysql database connection in JSP page.
    Needed details on:
    1) what are all the mysql drivers need to be included.
    2) what is the syntax for establish a database connection

    hi,
    http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.htmlsee down for mysql config with tomcat

  • Problem in Oracle Database Connectivity in JSP

    I am having big problem such as Oracle Database connectivity problem
    Following code i am used for database connection. but it throw an exception call class not found exception.
    Pls any one can help me. With a sample code for Oracle Database connection in JSP
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    String url="jdbc:oracle:thin:@172.25.44.54:1521:bbo";
    con = DriverManager.getConnection(url,"user", "user123");
    Thank you

    Well i've never used oracle or their drivers before but i'm presuming that you'd go to oracle.com or something and look for downloads. Otherwise you could goodle for Oracle JDBC drivers. Then just follow the instructions.
    Again i've never used JSP but if you have a manifest file somewhere you'll need to put a class-path: entry in their referecning the jar file with the driver so that it is availble at run-time.
    Wes

  • Sql database connection in jsp

    Hi,
    I am new to java.
    I know how to connect the database in the java using the javacodings [jdbc] but i am don't know how to connect the database using the jsp.
    Is it easy. If so, can any one help me in this regards.
    Any sample codes or white paper available.
    thanks in advance,
    Regards,
    sa

    Hi,
    Here's a simple application i write to test JSTL.
    Using JSTL is easier.
    Create a directory named tests in your webapps tomcat directoty.
    In this, create a web-inf dir and inside a lib dir.
    Copy JSTL.JAR ans STANDARD.JAR in tests/web-inf/lib/ which are lib for JSTL (found on apache foundation web site, jakarta implementation).
    Copy you jdbc driver in jakarta-tomcat/common/lib dir.
    Here is a file to input some data from an HTML form:
    Create saisie.jsp and record.jsp in you tests apps dir.
    saisie.jsp:
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <html>
    <head>
    <title>Simple Example</title>
    </head>
    <body>
        <h1> Saisie de donn�es  </h1>
        <form name="saisie" action="record.jsp" method="get">
            Code :<input type="text" name="code"/>
            Text :<input type="text" name="text"/>
            <input type="submit" name="submit"/>
        </form>
    </body>
    </html>and record.jsp:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ page isELIgnored ="false" %>
    <html>
    <head>
    <title>Simple Example</title>
    </head>
    <body>
    <sql:query var="result"  maxRows="100">
         select * from ess
    </sql:query>
    <table>
         <!-- Affichage de l'ent�te avec le nom des colonnes -->
         <tr>
         <c:forEach var="name" items="${result.columnNames}">
              <th>${name}</th>
         </c:forEach>
         </tr>
         <!-- Affichage des donn�es avec 'rowsByIndex' -->
         <c:forEach var="ligne" items="${result.rowsByIndex}">
         <tr>
              <c:forEach var="valeur" items="${ligne}">
                   <td>${valeur}</td>
              </c:forEach>
         </tr>
         </c:forEach>
    </table>
    <c:set var="code_id" value="${param.code}"/>
    <sql:update>
        INSERT INTO ESS (ID,TEXT) VALUES (?,?)
        <sql:param>${param.code} </sql:param>
        <sql:param>${param.text}</sql:param>
    </sql:update>
    </body>
    </html>Here's web.xml file to create in tests/web-inf dir:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <description>Learning JSTL (or whatever you like</description>
        <context-param>
              <param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
              <param-value>jdbc:postgresql://127.0.0.1/gihe,org.postgresql.Driver,gihe,****<param-value>
         </context-param> 
    </web-app>web.xml contains the datasource definition, the jdbc driver, the url, user and password.
    saisie.jsp is a standard html file.
    record.jsp use web.xml datasource to connect to the database and use JSTL tag to insert some data.
    more explanations on java sun site.

  • Database Connection Problem, JSP, Tomcat5.5.9, Oracle9i

    hi,
    Am trying to make database connection using Oracle9i thin driver, what am doing is:
    I put classes12.zip and classes12_dms.jar in the classpath and also added these libraries in netbeans library folder.
    I make jsp page like this --------
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.util.*, java.sql.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Testing Page</title>
    </head>
    <body>
    <%
    String url = "jdbc:oracle:thin:@SERVERNAME:1521:DBNAME";
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url,"scott","tiger");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from person order by name");
    %>
    <h1>Testing Page</h1><hr>
    <table border="1">
    <tbody>
    <tr>
    <th>Name</th>
    <th>Email</th>
    </tr>
    <% while(rs.next()) {%>
    <tr>
    <td><%= rs.getString(1)%></td>
    <td><%= rs.getString(2)%></td>
    </tr>
    <%
    rs.close();
    stmt.close();
    conn.close();
    } catch(ClassNotFoundException CNFEx) {
    out.println("<b>Error !</b><br>" + CNFEx.getMessage());
    } catch(Exception Ex) {
    out.println("<b>Error !</b><br>" + Ex.getMessage());
    %>
    </tbody>
    </table>
    </body>
    </html>
    when I run this page i got this error messages ----
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
    org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:138)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    root cause
    java.lang.NoClassDefFoundError
    oracle.jdbc.driver.OracleConnection.createDMSSensors(OracleConnection.java:506)
    oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:330)
    oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:485)
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:337)
    java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:79)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    any kind of help is appericiable.
    thanks.....

    I'd start by checking for a more recent driver version on Oracle's web site.
    Or: googling for "createDMSSensors" (the "root cause" in the stack trace) has as the first hit: Re: Java Help Please! HttpServlet doFilter() Exception

  • Database Connection problem (JSP, Oracle & Tomcat 5.5)

    I am trying connect to Oracle 8 database through JSP and the webserver is Tomcat5.5. The classes.jar file is in the Tomcat5.5\common\lib directory and the path has also been set to mentioned directory. But I am getting exceptions. The code and the error are given below.
    Need help at the earliest.
    Thanks in advance.
    CODE
    Class.forName ("oracle.jdbc.driver.OracleDriver");     
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@insrs013:1521:GCR","BILLING_USER", "BILLING_USER");
    PreparedStatement pstmt = null;
    ResultSet rs = null;     
    pstmt = con.prepareStatement("INSERT INTO PROJECTIP(PROJECTID, PROJECTSERVERNAME, SERVERIP) VALUES(?,?,?)");
    ERROR
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: oracle.jdbc.driver.OracleDriver
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
         org.apache.jsp.test.ServerIPDataSave_jsp._jspService(org.apache.jsp.test.ServerIPDataSave_jsp:137)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1338)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1187)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:127)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
         java.lang.ClassLoader.loadClassInternal(Unknown Source)
         java.lang.Class.forName0(Native Method)
         java.lang.Class.forName(Unknown Source)
         org.apache.jsp.test.ServerIPDataSave_jsp._jspService(org.apache.jsp.test.ServerIPDataSave_jsp:71)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    Hope is only the love of life.

    hi,
    FIrst make one thing clear. By classes.jar you mean either classes111.jar or classes12.jar.Right?If not,please check tht.
    Also,u needn't set any classpaths for Tomcat.
    Regards,
    Viswanath.

  • Sharing Portal database connection with JSP page

    Hi out there,
    I implemented a JSP page as a selection form to be integrated into Oracle Portal. This JSP page contains a 'dynamic' form which needs to send queries to the database also integrated in the Portal.
    For this I am currently using a JDBC connection but I would prefer to use the internal db connection of the Portal System.
    Explanation: The user has to log in to the Portal and after that can call the JSP form. To poulate some comboboxes within this form I need some data from the database and the user does have READING privileges on that database.
    Can anybody tell me how to use the user's login and password (or the established connection) to fetch the needed data from the database OTHER than with a jdbc connection?
    Thanx in advance!
    Cheers,
    Thomas

    sorry. not going to happen. you're running in a completely different environment when running Java on Portal. Portal is running in the database; your Java is running on the application server. your Java code must use JDBC to access any database resources, even if Portal related.
    it is essential that you implement a connection pool on the application server to optimize your database traffic. check out bitmechanic for a very good open source option.
    good luck,
    rich

  • Database connection through JSP

    I am trying to connect JSP to MySql database.
    <body>
    <div id="container">
         <div id="containerleft">
         <!--     <img src="wildfern.jpg" width=200 height=1000> -->
         </div>     
    <div id="containerright"><center><h1>List Of Deliverables</h1></center><br><br>
    <table cellpadding="10">
    <tr>
    <td><h3> Number of Deliverables</h3></td>
    <td><input type="text" name="deliverableSize" size="20" onchange="DynamicBox(deliverableSize.value)"></td>
    <td></td>
    </tr>
    <tr></tr>
    <tr></tr>
    </table>
    <table>
    <tr>
    <td><h3><center>  Week</center></h3></td>
    <td><center><h3>       Deliverable name       </h3></center></td>
    <td></td>
    <td><center><h3>Weightage </h3></center></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <% 
                              try
                              Class.forName("com.mysql.jdbc.Driver");
                                catch(ClassNotFoundException e)
                                    out.println("Class nai milli bhai");
                                Connection dbh=null;
                               try
                                   dbh=DriverManager.getConnection("jdbc:mysql://172.20.200.21/B2","B2","ignite#1234");         
                                   Statement stmt = dbh.createStatement();
                                    String query = "select * from Parameters_Details;";
                                    ResultSet rs = stmt.executeQuery(query);
                                     while(!rs.next())
                                 %>       
                                 <td><%=rs.getString(2)%> </td>   
                                 <%  
                               }catch (SQLException sqle)
                                    System.out.println("SQL Error : " + sqle);
                               catch(Exception e)
                                   System.out.println("HELLLO"+e);
                               finally
                               //    dbh.closeConnection();
                                %>   
                                   <%--<td></td>
    <td></td>
    <td><center><h3> Core</h3></center></td>
    <td><center><h3>    SE</h3></center></td>
    <td><center><h3>      PE</h3></center></td>--%>
    </tr>
    </table>
    <div id="bottom">
    </div>
    <center> <input type="submit" value="Create" name="Submit">
    <input type="reset" value="Reset" name="Cancel"></center>
    </div>
    </div>
    </form>
    </body>
    It is showing following Exception.
    1>> org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
    2>> java.lang.ClassNotFoundException: org.apache.jsp.DeliverablesList_jsp

    1)<%--<td></td>
    <td></td>
    <td><center><h3>Core</h3></center></td>
    <td><center><h3>SE</h3></center></td>
    <td><center><h3>PE</h3></center></td>--%>
    :- Jasper exception indicates that it seems syntax error . You need to check out your code carefully. Give comments like this
    <% // %> OR <% /* */ %>.
    Or if you wanna comment only html code use <!-- <td> --> like this.
    Second thing why did you write while( !rs.next()) ? it should be while(rs.next())
    Best luck.

  • Oracle Database Connection using JSP

    I am attempting to create a simple web app using Oracle 9i and JSP. I am trying to create a connection to my database and do not seem to be having much luck. I have worked with ASP and can find my way around fairly well in that environment, however, JSP seems to be not as closely related as I initially thought. Can anyone point me to a good site that can give a beginner the basics on using this technology. I have been to several sites off of Oracle and Sun, but I seem to be more confused after reading them. With JSP, can I code as I would in ASP i.e JavaScript, etc? I have downloaded and installed the JDBC drivers from Oracle's website, but I receive errors when trying to establish a connection. If there is a site that can explain from the ground up how to set up a connection, I would be very greatful!

    Hi,
    This example uses Interbase, but hopefully you will find it useful anyway -
    http://www.kpi.com.au/interbase/connect.jsp
    Cheers,
    Lars

  • Error due to accessing database connection using jsp

    Hi,
    I have an error, during accessing a datbase using jsp:useBean from jsp.Urgent i need this one
    my source code is
    DbBean.java
    package SQLBean;
    import java.sql.*;
    import java.io.*;
    public class DbBean implements java.io.Serializable{
    private String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    private Connection dbCon;
    public DbBean(){
    super();
    public boolean connect() throws ClassNotFoundException,SQLException{
    Class.forName(dbDriver);
    dbCon = DriverManager.getConnection("jdbc dbc:mybean","","");
    return true;
    public void close() throws SQLException{
    dbCon.close();
    public ResultSet execSQL(String sql) throws SQLException{
    Statement s = dbCon.createStatement();
    ResultSet r = s.executeQuery(sql);
    return (r == null) ? null : r;
    public int updateSQL(String sql) throws SQLException{
    Statement s = dbCon.createStatement();
    int r = s.executeUpdate(sql);
    return (r == 0) ? 0 : r;
    database.jsp
    <HTML>
    <HEAD><TITLE>DataBase Search</TITLE></HEAD>
    <BODY>
    <%@ page language="Java" import="java.sql.*" %>
    <jsp:useBean id="db" scope="application" class="SQLBean.DbBean" />
    <jsp:setProperty name="db" property="*" />
    <center>
    <h2> Results from </h2>
    <hr>
    <br><br>
    <table>
    <%
    db.connect();
    ResultSet rs = db.execSQL("select * from employ");
    int i = db.updateSQL("UPDATE employ set fname = 'hello world' where empno='000010'");
    out.println(i);
    %>
    <%
    while(rs.next()) {
    %>
    <%= rs.getString("empno") %>
    <BR>
    <%
    %>
    <BR>
    <%
    db.close();
    %>
    Done
    </table>
    </body>
    </HTML>
    The error like this
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    error: Invalid class file format in C:\Program Files\Apache Tomcat 4.0\webapps\muthu\WEB-INF\classes\SQLBean\DbBean.class. The major.minor version '49.0' is too recent for this tool to understand.
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:65: Class SQLBean.DbBean not found.
    SQLBean.DbBean db = null;
    ^
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:68: Class SQLBean.DbBean not found.
    db= (SQLBean.DbBean)
    ^
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:73: Class SQLBean.DbBean not found.
    db = (SQLBean.DbBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "SQLBean.DbBean");
    ^
    4 errors, 1 warning
    Anybody help me?
    Thanx in advance

    Your code is ok . The problem is in java version witch you use to compile the DbBean class . I think you are using java 1.5 try to change to 1.4 compile and run again should help .

  • Database connection to jsp page

    I have a data entry form in HTML and done validation in javascript.
    From that form the values entered by the user, is displayed on JSP page by method.
    <%=request.getParameter(" ")%
    MY problem is:
    i want that the values shown by the jsp page, is submitted or saved into database automatically, when i click submit button on the page.
    How can i do this.
    I have to use jdbc driver to make a connection for the database.
    plzz help me, as it is very urgent.
    my jsp page is as follow:
    <%@ page language="java" import="java.sql.*" %>
    <html>
    <head>
    <title></title>
    <body>
    <%
    try {
    //Load the jdbc driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //Create a connection object
    Connection con=DriverManager.getConnection("jdbcdbc:jspsql","java","java");
    System.out.println("got connection");
    // Create a statement object and call its executeUpdate method to insert a record
    Statement s=con.createStatement();
    String sql = "INSERT INTO Gl_Mast VALUES ('1','ABHI','120','520')";
    s.executeUpdate(sql);
    // Step 4. Use the same Statement object to obtain a ResultSet object
    sql = "SELECT GL_CODE, GL_DESCR FROM Gl_Mast";
    ResultSet rs = s.executeQuery(sql);
    while (rs.next()) {
    out.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
    rs.close();
    s.close();
    con.close();
    catch (ClassNotFoundException e1) {
    // JDBC driver class not found, print error message to the console
    System.out.println(e1.toString());
    catch (SQLException e2) {
    // Exception when executing java.sql related commands, print error message to the console
    System.out.println(e2.toString());
    catch (Exception e3) {
    // other unexpected exception, print error message to the console
    System.out.println(e3.toString());
    %>
    <form name="display" ACTION="" >
    <table width="100%" border="3">
    <tr>
    <TD COLSPAN=5><center><h3><b><i>GL MASTER INFORMATION</i></b></h3></center></TD>
    </TR>
    <tr>
    <th>Code No.</th>
    <th>Description</th>
    <th>Dr. Amount</th>
    <th>Cr. Amount</th>
    <th>Type</th>
    </tr>
    <tr>
    <td> <%=request.getParameter("code")%></td>
    <td> <%=request.getParameter("Description")%></td>
    <td> <%=request.getParameter("DrAmount")%></td>
    <td> <%=request.getParameter("CrAmount")%> </td>
    <td> <%=request.getParameter("type")%></td>
    </tr>
    </table>
    <p>
    <INPUT TYPE="submit" VALUE="SAVE" >
    <INPUT TYPE="button" VALUE="BACK" onClick="history.go(-1)">
    </body>
    </html>
    thanx..
    abhijit

    X POST

  • Database connection with jsp?

    any database (access preferred)

    kajbj wrote:
    What's the question?"give me teh codez", of course. ;-)

  • DATABASE CONNECTIVITY PROBLEM IN JSP

    Hello Friends .
    I am facing problem in database connectivity with JSP . Following is the code .
    <%
    String accessDBURLPrefix = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    String accessDBURLSuffix = ";DriverID=22;READONLY=false}";
    String databaseURL = accessDBURLPrefix + "db1.mdb" + accessDBURLSuffix;
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection con = java.sql.DriverManager.getConnection(databaseURL, "", "");
    out.println("Connection created sucessfully");
    catch(Exception e)
    out.println(e);
    %>
    It gives following output :
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
    If I run the code in core java application then it works sucessfully .
    Plz help me to find the solution .
    I am using sun studio Enterprise 8.1
    have stored the access file in web direcotry in the project.
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Please use CODE tags when posting code. You are losing some of the plus signs of string concatenation to the forum's formatting beast.
    Preferred solution: Don't use Access as a database. The JDBC-ODBC bridge is always troublesome.
    If you must use Access...
    Well the message is easy enough to understand: it can't find the database db1.mdb.
    You say you put db1.mdb in the web directory. Obviously the computer is not looking there (silly computer for not looking where you put the file)
    So it is up to you to be smart and tell the computer exactly where to go.
    Using application.getRealPath("/db1.mdb") in place of "db1.mdb" will probably work in a JSP.
    String databaseURL = accessDBURLPrefix  + application.getRealPath("/db1.mdb") +  accessDBURLSuffix;cheers,
    evnafets

  • Jsp and database connection using bean

    * I want create a bean to handle database connectivity.The
              <jsp:usebean> tag uses
              no argument constructor ..so I cannot pass the userid and password to
              the constructor.
              So how can I create a database connection when the user_id and password
              will be a part of parameter ?
              * Now I'm opening database connection in the jsp scriplets. Everytime I
              refresh the
              jsp page a new connection is created ? Is it not going to choke the
              database ? I cannot use connection pool because every user logs in with
              different userid.
              Thanks
              

    You can pass your arguments in this way:
              <jsp:usebean id="myBean" scope="page"/>
              <jsp:setProperty name="myBean" property="userId", value=<%= user_id%>/>
              <jsp:setProperty name="myBean" property="password", value=<%=
              user_password%>/>
              of course, in your bean class, you should create two setter methods,
              setUserId and setPassword.
              Hopefully, this will help you.
              sonia WEN
              Chiranjib Misra wrote:
              > * I want create a bean to handle database connectivity.The
              > <jsp:usebean> tag uses
              > no argument constructor ..so I cannot pass the userid and password to
              > the constructor.
              > So how can I create a database connection when the user_id and password
              > will be a part of parameter ?
              >
              > * Now I'm opening database connection in the jsp scriplets. Everytime I
              > refresh the
              > jsp page a new connection is created ? Is it not going to choke the
              > database ? I cannot use connection pool because every user logs in with
              > different userid.
              >
              > Thanks
              

Maybe you are looking for