How to Connect Database Through JSP

How to connect the database in jsp?

<form name='toolscode' target="cond_desc" action="conddesc.jsp"> <%
 Connection con= null;
 Statement stmt = null;
 ResultSet res=null;
 try{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  con = DriverManager.getConnection("jdbc:odbc:nncea","ceatest","test");
  stmt = con.createStatement();
  //res = stmt.executeQuery ("SELECT DISTINCT ORDITEMORDCODE from CEAORDITEMS WHERE PRINCIPALNAME= '" + principal_name2 + "';");  %>

  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="73">
    <tr>
      <td nowrap bgcolor="#C6E2FF"  class="heading" width="150" height="20" align="center">
    <span style="background-color: #C6E2FF; font-weight:700">
                <font size="2" face="Sylfaen">Condition Name</font></span><font face="Sylfaen" size="2">&nbsp;
                </font>
   </td>
  </tr>
  <tr>

      <td width="150" bgcolor="#C6E2FF" height="51" align="center">
        <p style="margin-top: 3; margin-bottom: 3" align="center">
              <span style="background-color: #C6E2FF; font-weight:700">
     <font face="Sylfaen" size="1" color="#FFFFFF">
      <SELECT NAME ="Condi_Name" Target = "conddesc.jsp" style="border: 1px solid #8AB0FF" onChange='submit()'>
   <%
    res = stmt.executeQuery ("SELECT DISTINCT ltrim(rtrim(CONDITIONNAME)) from CEATEMPSTORE;");
    while(res.next()){%>
    <OPTION> </OPTION>
    <OPTION><%=res.getString(1)%></OPTION>
    <%}%></SELECT></font></p>
   </td>
   </tr>
  </table>
 <% }  // end try
  catch(Exception ex)
   {
    System.err.print("...: " + ex.toString());
   }//end catch
   finally
   {
    //res.close();
    stmt.close();
    con.close();
   }
  %> </form>

Java Tips by :Sowjanya Devi Uddaraju

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.