JSP with MySQL connection in Tomcat6.0.20

Hi i'm using MySQL5.1, Tomcat6.0.20 in my project, There i'm not able to connect to the database. it's giving the error.
My program is :
<%@ page language="java" import="java.sql.*" %>
<%
     String driver = "org.gjt.mm.mysql.Driver";
     Class.forName(driver).newInstance();
     try{
          String url="jdbc:mysql://localhost/books?user=root@localhost&password=india123";
          Connection con=DriverManager.getConnection(url);
          Statement stmt=con.createStatement();
     catch(Exception e){
          System.out.println(e.getMessage());
     if(request.getParameter("action") != null){
          String bookname=request.getParameter("book_name");
          String author=request.getParameter("author");
          stmt.executeUpdate("insert into books_lib(book_name,author) values('"+bookname+"','"+author+"')");
          ResultSet rst=stmt.executeQuery("select * from books_lib");
          %>
          <html>
          <body>
          <center>
               <h2>Books List</h2>
               <table border="1" cellspacing="0" cellpadding="0">
               <tr>
                    <td><b>S.No</b></td>
                    <td><b>Book Name</b></td>
                    <td><b>Author</.b></td>
               </tr>
                    <%
                    int no=1;
                    while(rst.next()){
                    %>
                    <tr>
                    <td><%=no%></td>
                    <td><%=rst.getString("book_name")%></td>
                    <td> <%=rst.getString("author")%> </td>
                    </tr>
                    <%
                    no++;
     rst.close();
     stmt.close();
     con.close();
%>
               </table>
               </center>
          </body>
     </html>
<%}else{%>
     <html>
     <head>
          <title>Book Entry FormDocument</title>
          <script language="javascript">
          function validate(objForm){
               if(objForm.bookname.value.length==0){
               alert("Please enter Book Name!");
               objForm.bookname.focus();
               return false;
               if(objForm.author.value.length==0){
               alert("Please enter Author name!");
               objForm.author.focus();
               return false;
               return true;
               </script>
          </head>
          <body>
               <center>
<form action="BookEntryForm.jsp" method="post" name="entry" onSubmit="return validate(this)">
     <input type="hidden" value="list" name="action">
     <table border="1" cellpadding="0" cellspacing="0">
     <tr>
          <td>
               <table>
                    <tr>
                    <td colspan="2" align="center">
<h2>Book Entry Form</h2></td>
                    </tr>
                    <tr>
                    <td colspan="2"> </td>
                    </tr>
                    <tr>
                    <td>Book Name:</td>
                    <td><input name="bookname" type="text" size="50"></td>
                    </tr>
                    <tr>
                    <td>Author:</td><td><input name="author" type="text" size="50"></td>
                    </tr>
                    <tr>
                         <td colspan="2" align="center">
<input type="submit" value="Submit"></td>
                         </tr>
                    </table>
               </td>
          </tr>
     </table>     
</form>
               </center>
          </body>
     </html>
<%}%>
The error page is:
HTTP Status 500
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 19 in the jsp file: /singleupload/BookEntryForm.jsp
stmt cannot be resolved
16:      if(request.getParameter("action") != null){
17:           String bookname=request.getParameter("book_name");
18:           String author=request.getParameter("author");
19:           stmt.executeUpdate("insert into books_lib(book_name,author) values('"+bookname+"','"+author+"')");
20:           ResultSet rst=stmt.executeQuery("select * from books_lib");
21:           %>
22:           <html>
An error occurred at line: 20 in the jsp file: /singleupload/BookEntryForm.jsp
stmt cannot be resolved
17:           String bookname=request.getParameter("book_name");
18:           String author=request.getParameter("author");
19:           stmt.executeUpdate("insert into books_lib(book_name,author) values('"+bookname+"','"+author+"')");
20:           ResultSet rst=stmt.executeQuery("select * from books_lib");
21:           %>
22:           <html>
23:           <body>
An error occurred at line: 45 in the jsp file: /singleupload/BookEntryForm.jsp
stmt cannot be resolved
42:                     no++;
43:      }
44:      rst.close();
45:      stmt.close();
46:      con.close();
47: %>
48:                </table>
An error occurred at line: 46 in the jsp file: /singleupload/BookEntryForm.jsp
con cannot be resolved
43:      }
44:      rst.close();
45:      stmt.close();
46:      con.close();
47: %>
48:                </table>
49:                </center>
Stacktrace:
     org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
     org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
     org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Please help me

?An error occurred at line: 20 in the jsp file: /singleupload/BookEntryForm.jsp stmt cannot be resolved
That means it can't see any variable declared called "stmt"
There isn't one at this point.
The stmt variable you have declared up above, is nested in curly braces - within your try/catch statement. As such it only has scope within those curly braces. If you want to use stmt outside of the try block, you need to declare stmt outside of it.
And yes, I echo Balusc's comments about scriptlet code in a jsp page.
A better solution would be to write a java class with a method that does the database query, and returns a List of objects.
Your JSP can then take that list of objects and display them on the page.
Its a bit more work, but makes the code much easier to write/maintain/test because you separate out the "data" and "view" layers.

Similar Messages

  • PleaseHelp on jsp and Mysql connectivity and a lot of exception errors

    Hi,
    I am Trying to connect a JSP page with Mysql database. I am having a lot of probelms. After having a lot of problems in connecting the JSp with Mysql. Intilally it was giving me the exception error that " NO appropriate driver was found. After modifying the URl it was fine. Now It is giving the Following errors.
    servlet.ServletException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE: Unexpected end of input stream
    In a window before loading the Explorer page it is giving the following error that The port 8081 is already in use and i should expand to other ports. Noraml JSP Files which used to work before are also not working .
    Internal Tomcat JWSDP is alos not working. If i try to start the server it says that port 8081 is already in USe . A java.net.connection exception is also occuring. The normal JSP files are also not working. What is Happening. I am also giving the code i have writted. PLease tellme why so many exception errors are occuring.
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8081/mis_project", "root", " ");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("Select study_semester FROM Semester");
    while(rs.next()) {
    %>
    <option value="<%= rs.getString("Study_Semester") %>">
    </option>
    <% }
    if(rs!=null) rs.close();
    if(stmt!=null) stmt.close();
    if(con!=null) con.close();
    I am trying to connect to Mysql and automatocally populate a field in a Form in later JSp pages i intend to record the data entered in these fields into other tables.

    <%
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/myDB?user=username&password=mypass");
    Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
    String cat = "";
              try{
              cat = request.getParameter("category");
              }catch(NullPointerException npe){}
              ResultSet rs = stmt.executeQuery("SELECT id,fullname FROM users WHERE category LIKE '%motor%' AND subcategory like '%"+cat+"%'");
         %>
    This piece gets a category parameter from a form post and uses it to search for a specific category in a database table. I think maybe u need to download JConnector from mysql site and unzip it to the classes folder of your WEB-INF in Tomcat server...... i hope this helps a bit

  • JSP and MySql Connectivity in Fedora core 4

    Dear all,
    We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help....

    Dear all,
    We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help....

  • JSP with MYSQL 4.0

    May i know is JSP works well with MYSQL 4.0 database?

    Yaah..it works perfectly OK....just download the required driver my mysql site only & ur ready to develop applications is JSP using mysql.

  • Need help with MySQL connection error _mmServerScripts

    Trying to create insert a recordset I got the message:
    "The files from the _mmServerScripts folder are for the server model PHP-MySQL. You try to connect to a database using a different server model .Please remove this folder outside the Dreamweaver environment on both local and testing machines and try again."
    I've searched the net and have seen this message hunting people since dw8...
    I could not find a "cure".
    Things to notice:
    0 - Yes the whole thing is apache/php/mysql... just DW thinks it's not.
    1 - Both the connection and the Recordset actualy works. I have a whole site based on this connection and the recorsets I've created manualy based on it.
    2 - It does not matter if we erase or not the _mmServerScripts folder the message stands still allover.
    3 - The problem seems to show up when you split servers...
    3.1 - If I test in a WAMP environment where apache and mysql are in the same machine I can use DW to create data objects for me.
    3.2 - If I test in my real test environment which have web server and db server separated from each other then I can't use DW to create data objects, see bindings, behaviours etc... all I get is this message.... while the code itself runs fine anyway.
    Does any one already knows how to work around or fix this?
    Thanks,
    Julio

    Thanks PZ,
    Yes everything is fine with the site definition.
    everything works. I can upload, run, test all ok.
    The only thing that does not work is to insert any sort of data object through DW interface. If I declare my reordsets by hands or even If I use the ones DW created in my local test server all works fine.
    Then if I use the site definition and try to see any bindings or create a recordset or create a new connection using dw... then the messages come up and dw can't go any further in that task.
    By spli servers I mean one phisical linux server with apache/php but without mySQL + one physical Linux server with mySQL but without apache/php.
    So when I use a site definition that points either to a WAMP or LAMP i.e. when everything is in the same machine DW goes happy and does whatever it's asked to do.
    When I try that on the real mccoy environment (with the two separated servers)... It looks like DW gets confused...

  • Help with mySQL Connection string

    Here is hoping someone can help & once I get it down I promise I'll post all my work on this list so some other newbie can benefit.
    I'm simply trying to run a very very straightforward JDBC test with mySQL & I keep getting the "Server configuration denies access to data source" error. But before you tell me that I must simply look at what my mysql.db & mysql.user table allows - I'VE TRIED THAT. I realize that the error is probably there somewhere - but I can't see it.
    I've tried connecting with 2 different accounts - the provided "root" & a user I created "deep" to 2 different databases the provided "test" & "testdb" which I created) . Here is what mysql says about the two different databases
    mysql> select * from db;
    Host  | Db         | User |.......
    -----+------------+-------
    | %         | test    |       | ......
    | %         | test\_% |     | ........
    | localhost | testdb  | deep |........Note that "root" should have access to "test" & deep@localhost should have access to "testdb" right?
    So here are all the connection strings I have tried - all return the same error below
            Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test", "root", "mypass"
    //            "jdbc:mysql://localhost:3306/testdb", "deep", "mypass"
    //            "jdbc:mysql://localhost/testdb?user=deep&password=mypass"
    //            "jdbc:mysql://localhost/testdb", "deep", "mypass"
    //            "jdbc:mysql://localhost:3306/testdb?user=deep@localhost&password=mypass"
    //            "jdbc:mysql://localhost:3306/testdb?user=deep&password=mypass"
    //            "jdbc:mysql://localhost/testdb", "deep@localhost", "mypass"
    //            "jdbc:mysql:///test", "root", "mypass"
    //            "jdbc:mysql://localhost/test", "root@localhost", "mypass"
    );My Error:
    Exception in thread "main" java.sql.SQLException: Server configuration denies access to data source
            at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:193)
            at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
            at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
            at org.gjt.mm.mysql.Driver.connect(Driver.java:167)
            at java.sql.DriverManager.getConnection(DriverManager.java:517)
            at java.sql.DriverManager.getConnection(DriverManager.java:199)
            at TestMySQL4.main(TestMySQL4.java:76)BTW:
    I am using MacOSX 10.1
    MySQL 3.23.42
    The driver is: mm.mysql-2.0.6.jar
    Please help!
    'deep

    hi amandeep
    well i m getting the same error message when trying to connect MYSQL using mm.jdbc driver.
    java.sql.SQLException : Server configuration denies access to data base source.
    query.jdbcDriver org.gjt.mm.mysql.Driver
    query.databaseURL jdbc:mysql://aaa.bbb.com/pluto
    query.databaseUserName samin
    query.databasePwd samin
    query.summaries true
    i hve installed mysql on server aaa.bbb.com network 1
    and trying to run application on network 2
    Thanks
    samir

  • How to connect JSP with MySql Database?

    HI All...
    I want to know or How to connect Mysql with JSP or JSF any other software is available? please help me.....

    I want to know or How to connect Mysql
    with JSP or JSF any other software isavailable?
    please help me.....First you need to find 25 m of a CatV cable and...The DB files need to be located on the ninth device of a SCSI Daisy Chain with the total SCSI cable length being over 150 m (and the devices (and cables) need to be mix of Differential and Non-Differential).
    Edit: And forget the terminator, who needs it?

  • JSP with mysql database

    *********************This is my HTML form for Media search*****************
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1"
    http-equiv="content-type">
    <title>search media form</title>
    </head>
    <body>
    <form name="search" action="med_search.jsp"> <big
    style="font-weight: bold; color: rgb(0, 102, 0);">Media
    : Search<br>
    </big>
    <hr
    style="height: 1px; width: 50%; margin-left: 0px; margin-right: auto;"><label>Media
    :   equals :</label><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
    <select size="1" name="msearch_name">
    <option>-All-</option>
    <option>100% Home Girls</option>
    <option>1800mumanddad</option>
    <option>2D Max</option>
    <option>Access all areas</option>
    <option>Adelaide Advertiser</option>
    <option>Adelaide Messenger</option>
    <option>Adelaide Sunday Mail TV guide</option>
    <option>All Media</option>
    <option>Ari Reserved</option>
    <option>Austar</option>
    <option>Blockbuster</option>
    <option>Brisbane Courier Mail</option>
    <option>Brisbane Quest</option>
    <option>Brisbane Sunday Mail- TV guide</option>
    <option>Cleo</option>
    <option>Community</option>
    <option>Cosmo</option>
    <option>Day Time TV</option>
    <option>Dolly</option>
    <option>Edge</option>
    <option>Empire</option>
    <option>EMS</option>
    <option>Explode</option>
    <option>Facing Sanity</option>
    <option>Fairfax</option>
    <option>FHM</option>
    <option>Foxtel</option>
    <option>Funkysexycool</option>
    <option>Gametel newsletter</option>
    <option>Gametel Sim Pack</option>
    <option>Gametel UI 1st Version</option>
    <option>Gametel UI 2nd Version</option>
    <option>Gametel Website</option>
    <option>Geelong Advertiser-TV guide</option>
    <option>Girlfriend</option>
    <option>Good Medicine</option>
    <option>Herald Sun</option>
    <option>Home Girls</option>
    <option>Insight</option>
    <option>MailBlast</option>
    <option>Maximum Performance</option>
    <option>Melboume Leader</option>
    <option>Mobile</option>
    <option>Mobile Pet-Ari</option>
    <option>Money Saver</option>
    <option>Motor Show Mag</option>
    <option>Mr.Wisdoms Whopper</option>
    <option>MTV</option>
    <option>Music Australia</option>
    <option>New Chat</option>
    <option>New Idea</option>
    <option>NW Magazine</option>
    <option>One Love</option>
    <option>Optus</option>
    <option>Penthouse</option>
    <option>People</option>
    <option>Picture</option>
    <option>Picture Premium Edition</option>
    <option>Picture Premium Special</option>
    <option>Platinum Girls</option>
    <option>Phychic Business Cards</option>
    <option>Phychic Calender</option>
    <option>Phychic CD Cover</option>
    <option>Ralph</option>
    <option>Sain Magazine</option>
    <option>Sanity Chart</option>
    <option>Series 40 gametel subscriber</option>
    <option>Series 60 gametel community</option>
    <option>Series 60 gametel non-subscriber</option>
    <option>Series40 non-subscriber</option>
    <option>Smash Hits</option>
    <option>SMS Chat</option>
    <option>Soap World</option>
    <option>SPAM</option>
    <option>STM-WA</option>
    <option>Stupid People Line</option>
    <option>Sunday Herald Sun TV guide</option>
    <option>Sunday Telegraph TV guide</option>
    <option>Sunday Times TV guide</option>
    <option>Sydney Cumberland</option>
    <option>Sydney Daily telegraph</option>
    <option>Take 5</option>
    <option>Tasmania TV guide</option>
    <option>That's Life</option>
    <option>Total Gamer</option>
    <option>TV 10</option>
    <option>TV 7</option>
    <option>TV 9</option>
    <option>TV Hits</option>
    <option>TV Soap</option>
    <option>TV Week</option>
    <option>UNASSIGNED</option>
    <option>Urban Hits</option>
    <option>VH1</option>
    <option>Video Ezy</option>
    <option>Vogue Girl</option>
    <option>WAP</option>
    <option>Web Competitions</option>
    <option>Website</option>
    <option>West Magazine</option>
    <option>Western Australian</option>
    <option>What DVD</option>
    <option>What's Hot on Video</option>
    <option>Witchcraft</option>
    <option>Women's Day</option>
    <option>xxx</option>
    </select>
    <br>
    <span style="font-weight: bold;"><span
    style="color: rgb(0, 102, 0);"><span
    style="font-weight: bold;"><span
    style="font-weight: bold;"></span></span></span></span></big><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
          </big><big
    style="color: rgb(0, 102, 0);"><small><label
    style="color: rgb(0, 0, 0);">or
    is like :</label></small></big><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
    <textarea cols="20" rows="1" name="msearch_like"></textarea><br>
         </big><label
    style="color: rgb(0, 0, 0);">Media Type
    :</label><big style="font-weight: bold; color: rgb(0, 102, 0);">
    <select size="1" name="msearch_type">
    <option>-All-</option>
    <option>magazine</option>
    <option>newspaper</option>
    <option>other</option>
    <option>tv</option>
    <option>tv guide</option>
    </select>
    <br>
    <br>
    </big> <input name="med_search" value="Search"
    type="submit">  <input name="med_reset"
    value="Reset" type="reset"></form>
    <br>
    <br>
    </body>
    </html>
    //After clicking search button it will go to this jsp and gets the searched records.
    ***********************************med_search.jsp***********************
    <html>
    <body>
    <h1>Search Media</h1>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% PreparedStatement pstmt=null;%>
    <%
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    out.println("<table border=0>");
    if(request.getParameter("msearch_name").equals("-All-")&request.getParameter("msearch_type").equals("-All-"))
    %>
    <jsp:forward page="med_search.html"/>
    <%
    else if(!(request.getParameter("msearch_name").equals("-All-"))&!(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media.media_name,media.media_code,media_types.media_type,media_genders.media_gender,media.target_age,publishers.publisher,media.is_bookable,media_id from media,media_types,media_genders,publishers where media_name in (select media_name from media where media_type_id in (select media_type_id from media_types where media_type=" + "'" + request.getParameter("msearch_type") + "'" +") and media.media_name =" + "'" + request.getParameter("msearch_name") +"'" + ")and media.media_type_id=media_types.media_type_id and media.target_gender_id=media_genders.media_gender_id and media.publisher_id=publishers.publisher_id");
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    else if(!(request.getParameter("msearch_name").equals("-All-"))&&(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable,media_id from media me inner join media_types mt on me.media_type_id = mt.media_type_id inner join media_genders mg on mg.media_gender_id = me.target_gender_id inner join publishers pub on pub.publisher_id = me.publisher_id where media_name="+"'"+request.getParameter("msearch_name")+"'"+"") ;
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    else if(request.getParameter("msearch_name").equals("-All-")&!(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable,media_id from media me inner join media_types mt on me.media_type_id = mt.media_type_id inner join media_genders mg on mg.media_gender_id = me.target_gender_id left join publishers pub on pub.publisher_id = me.publisher_id where media_type=" + "'"+request.getParameter("msearch_type")+"'"+"");
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    ResultSet rst=pstmt.executeQuery();
    ResultSetMetaData rsmd=rst.getMetaData();
    int n=rsmd.getColumnCount();
    while(rst.next())
    out.println("<tr>");
    %>
    <td><form action="test.jsp" method="post"> <a href="t.jsp?media_id=<% out.print(rst.getString(8)); %>">Edit</a></form></td>
    <%
    out.print("<td>"+rst.getString(1)+"</td>");
    out.print("<td>"+rst.getString(2)+"</td>");
    out.print("<td>"+rst.getString(3)+"</td>");
    out.print("<td>"+rst.getString(4)+"</td>");
    out.print("<td>"+rst.getString(5)+"</td>");
    out.print("<td>"+rst.getString(6)+"</td>");
    out.print("<td>"+rst.getString(7)+"</td>");
    out.print("</tr>");
    }catch(Exception e)
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    //In this search output we have edit button for each row.After we click search it will enter into another form where we can edit the record.
    //In this jsp,i have designed the form for editing and displayed the current record values as initial values and after edit it must save and update the DB.But before I click save changes,its updating the DB with all zeros.
    ******************edit_search.jsp**************************************
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!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">
    <h1>Edit Search</h1>
    </head>
    <body>
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% String str1,str2,str3,str4,str5,str6;%>
    <%
    try
    int mgid=0;
    int tage=0;
    int pid=0;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    PreparedStatement pstmt=con.prepareStatement("SELECT media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable FROM media m INNER JOIN media_types met ON m.media_type_id = met.media_type_id INNER JOIN media_genders meg ON m.target_gender_id = meg.media_gender_id LEFT JOIN publishers pubs ON m.publisher_id = pubs.publisher_id where media_id=" + "'"+request.getParameter("media_id")+"'");
    ResultSet rs=pstmt.executeQuery();
    ResultSetMetaData rsmd=rs.getMetaData();
    int n=rsmd.getColumnCount();
    while(rs.next())
    %>
    <form method="post" action="">
    <label>Name</label> <%=rs.getString("media_name")%><br>
    <label>Code</label> <textarea cols="20" rows="1"name="med_code"><%=rs.getString("media_code")%></textarea><br>
    <label>Type</label> <%=rs.getString("media_type")%><br>
    <label>Target Gender</label>&nbsp
    <% PreparedStatement pstmt2=con.prepareStatement("SELECT media_gender FROM media_genders");
    ResultSet rst1=pstmt2.executeQuery();
    ResultSetMetaData rstmd2=rst1.getMetaData();
    int cnt1=rstmd2.getColumnCount();
    %>
    <select name="tar_gen">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("media_gender")+"<br>"%></option>
    <%
    %>
    </select><br>
    <label>Target Age</label> <textarea cols="20" rows="1" name="med_age"><%=rs.getString("target_age")%></textarea><br>
    <label>Publisher</label> 
    <%
    PreparedStatement pstmt1=con.prepareStatement("SELECT publisher FROM publishers");
    rst1=pstmt1.executeQuery();
    ResultSetMetaData rstmd1=rst1.getMetaData();
    int cnt2=rstmd1.getColumnCount();
    %>
    <select name="pub">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("publisher")+"<br>"%></option>
    <%
    %>
    </select><br>
    <label>Bookable</label> 
    <input type="checkbox">
    <%
    if (rs.getString("is_bookable").equals("1"))
    %>
    <checkbox maxlength="20" <checked></checkbox>
    <%
    else
    %>
    <checkbox maxlength="20" <unchecked></checkbox>
    <%
    %>
    <%
    str1=request.getParameter("med_code");
    PreparedStatement pst2=con.prepareStatement("select media_gender_id from media_genders where media_gender = "+ "'" + request.getParameter("med_gen") +"'");
    ResultSet rst2=pst2.executeQuery();
    while(rst2.next())
    mgid=rst2.getInt(1);
    rst2.close();
    str2=request.getParameter("med_gen");
    try
    tage=Integer.parseInt("'"+request.getParameter("med_age")+"'");
    catch(NumberFormatException e){}
    PreparedStatement pst3=con.prepareStatement("select publisher_id from publishers where publisher = "+ "'" + request.getParameter("pub")+"'");
    ResultSet rst3=pst3.executeQuery();
    ResultSetMetaData rsmd3=rst3.getMetaData();
    int nnn=rsmd3.getColumnCount();
    while(rst3.next())
    pid=rst3.getInt(1);
    rst3.close();
    //str4=request.getParameter("pub");
    try
    if(request.getParameter("bookable").equals("true"))
    str5="1";
    }catch(Exception e)
    str5="0";
    //str5=request.getParameter("bookable"");
    %><input name="med_edit" value="Save Changes" type="submit"><br></form>
    <%
    //out.println("<h2>2"+str1+"</h2>");
    PreparedStatement pstmt3=con.prepareStatement("UPDATE media set media_code="+str1+",target_gender_id="+mgid+",target_age="+tage+",publisher_id="+pid+" WHERE media_id="+"'"+request.getParameter("media_id")+"'");
    pstmt3.executeUpdate();
    //ResultSet res=.updateRow();
    //out.println("<h2>3"+str1+"</h2>");
    }catch(Exception e)
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    //This is another jsp which i replaced for edit_search.jsp.Functionality is same.And also giving the same result.But this is some what clear than edit_search.jsp.
    ****************************test.jsp******************************
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!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>JSP Page</title>
    </head>
    <body>
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% String str1=null;
    String str2=null;
    String str3=null;
    String mgid=null;
    String tage=null;
    String pid=null;
    %>
    <%
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    PreparedStatement pstmt=con.prepareStatement("SELECT media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable FROM media m INNER JOIN media_types met ON m.media_type_id = met.media_type_id INNER JOIN media_genders meg ON m.target_gender_id = meg.media_gender_id LEFT JOIN publishers pubs ON m.publisher_id = pubs.publisher_id where media_id=" + "'"+request.getParameter("media_id")+"'");
    ResultSet rs=pstmt.executeQuery();
    while(rs.next()){
    %>
    <form method="post" action="">
    <label>Name</label> <%=rs.getString("media_name")%><br>
    <label>Code</label> <textarea cols="20" rows="1"name="med_code"><%=rs.getString("media_code")%></textarea><br>
    <label>Type</label> <%=rs.getString("media_type")%><br>
    <label>Target Gender</label>&nbsp
    <% PreparedStatement pstmt1=con.prepareStatement("SELECT media_gender FROM media_genders");
    ResultSet rst1=pstmt1.executeQuery();
    %>
    <select name="tar_gen">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("media_gender")%></option>
    <%
    %>
    </select><br>
    <label>Target Age</label> <textarea cols="20" rows="1" name="med_age"><%=rs.getString("target_age")%></textarea><br>
    <label>Publisher</label> 
    <%
    PreparedStatement pstmt2=con.prepareStatement("SELECT publisher FROM publishers");
    ResultSet rst2=pstmt2.executeQuery();
    %>
    <select name="pub">
    <%
    while(rst2.next())
    %>
    <option><%=rst2.getString("publisher")%></option>
    <%
    %>
    </select><br>
    <label>Bookable</label> 
    <input type="checkbox">
    <%
    if (rs.getString("is_bookable").equals("1"))
    %>
    <checkbox maxlength="20" <checked></checkbox>
    <%
    else
    %>
    <checkbox maxlength="20" <unchecked></checkbox>
    <%
    str1=request.getParameter("med_code");
    PreparedStatement pstmt3=con.prepareStatement("select media_gender_id from media_genders where media_gender = "+ "'" + request.getParameter("med_gen") +"'");
    ResultSet rst3=pstmt3.executeQuery();
    while(rst3.next()){
    mgid=rst3.getString("media_gender_id");
    rst3.close();
    try
    tage=request.getParameter("med_age");
    catch(NumberFormatException e){}
    PreparedStatement pstmt4=con.prepareStatement("select publisher_id from publishers where publisher = "+ "'" + request.getParameter("pub")+"'");
    ResultSet rst4=pstmt4.executeQuery();
    while(rst4.next()){
    pid=rst4.getString("publisher_id");
    rst4.close();
    try
    if(request.getParameter("bookable").equals("true"))
    str3="1";
    catch(Exception e)
    str3="0";
    %>
    <input type="submit" value="Save Changes"><br></form>
    <%
    PreparedStatement pstmt5=con.prepareStatement("UPDATE media set media_code="+str1+",target_gender_id="+mgid+",target_age="+tage+",publisher_id="+pid+",is_Bookable="+str3+" WHERE media_id="+"'"+request.getParameter("media_id")+"'");
    pstmt5.executeUpdate();
    out.println("123"+"media_code"+str1+" gender"+mgid+"....age.."+tage+"publisher_id="+pid+" is_Bookable="+str3);
    catch(Exception e)
    out.println("ttttttttttt");
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    *********************************************************************

    I want to know or How to connect Mysql
    with JSP or JSF any other software isavailable?
    please help me.....First you need to find 25 m of a CatV cable and...The DB files need to be located on the ninth device of a SCSI Daisy Chain with the total SCSI cable length being over 150 m (and the devices (and cables) need to be mix of Differential and Non-Differential).
    Edit: And forget the terminator, who needs it?

  • Dependant lovs in jsp with mysql data

    hi to all.
    here is my doubt
    How to create dependant dynamic list of values in jsp where the data comes from mysql tables.(I mean i am storing all the details in mysql tables using foreign keys etc..).
    Ex.:country--->state--->district--->city--->
    we will be having this in most of the sites in general.
    Hope u got what i am looking for
    Expecting a very quick and excellent answer.
    thank you

    Within jsp pages it is not possible to have the comboboxes dynamically updated without intervention to either refresh the page with the new data or use java script.
    I had a similar problem which i resolved with java script :
    Interactive combo boxes on jsp
    Have a look at this thread for more info.

  • JSP with MYSQL.

    Dear Friends
    I have a unique problem in java, when i try to connect to mysql db.
    It shows an error message:
    Unable to load driver. Getting Connection ... SQLException: No suitable driverI am using mysql MySQL 4.1.9 and tomcat 5.5 version.
    though i have loaded the driver in lib directory, it still displays the same error
    messgae. Here is the jsp file which i use to connect to my database.
    http://localhost:8080/mysqljdbc.jsp
    <%@ page import="java.net.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.sql.*" %>
    <%
         try{
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         catch (Exception E) {
         out.println("Unable to load driver.");
         E.printStackTrace();
         try{
              out.println("Getting Connection ...");
              Connection C = DriverManager.getConnection("jdbc:mysql://localhost:3306/vinoth");
              out.println("<br>Connected:  " + !C.isClosed() + "<br>\n");
              out.println("Catalog:  " + C.getCatalog() + "<br>\n");
                   Statement S = C.createStatement();
                   ResultSet rs = S.executeQuery("SELECT * FROM foo");
                   ResultSetMetaData rsStruc = rs.getMetaData();
                   out.println("Table:  " + rsStruc.getTableName(1) + "<br>");
                   out.println("<table bgcolor=c8c8c8 cellpadding=5 cellspacing=1>");
                   out.println("<tr bgcolor=000000>");
                   int colCount = rsStruc.getColumnCount();
                   String colName = "";
                   for(int i=1;i <= colCount; i++){
                   colName = rsStruc.getColumnName(i) ;
                   out.println("<td><B><font color=white>" + colName + "</font></b></td>\n");
                   out.println("</tr>");
                   while (rs.next()) {
                   out.println("<tr bgcolor=ffffff>");
                   for(int i=1;i <= colCount; i++){
                   colName = rsStruc.getColumnName(i) ;
                   String fld = rs.getString(colName);
                        out.println("<td>" + fld + "</td>");
                   out.println("</tr>");
                   out.println("</table>");
                   rs.close();
                   C.close();
         catch (Exception E) {
          out.println("SQLException: " + E.getMessage());
    %>Now is there anything i have to configure apart from this.
    Thanx in advance.

    First things first...i definitely recommend you take out the db stuff out of the jsp page. Place the logic in a DAO and if you have to reference the dao in the jsp. Although in a practice you should have a service layer which does the db stuff. Use a servlet to call the service layer and pass the results of the service layer to the jsp.
    Writing java code like that in the jsp is just bad programming. There are loads of web frameworks that enable you to develop scalable web applications.
    I realise that this does not help you but it is a good idea to get the design correct before embarking on the development.

  • JSP with MYSQL on linux and windows2k

    I am using a linux box as a web server with tomcat and mysql. I aslo have a mirror on a Win2k machine running the same environment.
    I have a jsp file that uses a bean to update the database and it works on the win2k environment but not linux.
    In windows I see error messages in the tomcat console, how do I see these message on linux?
    Thank you,
    Paul.

    Did you check ALL of the files?
    There are files named "localhost_log.TODAYSDATE.txt", there are files named "catalina_log.TODAYSDATE.txt", and there's a file called "catalina.out".
    "catalina.out" appears to contain information very similar to the DOS output screen on the Windows platform.
    If those files don't have what you're looking for, then you'll have to get help from someone with more expertise than myself!

  • Dw 8 with mysql connection - no tables

    This is how the connection is setup
    http://img469.imageshack.us/img469/1408/1dy1.jpg
    This proves I have tables
    http://img443.imageshack.us/img443/6436/2qp8.jpg
    Now I am a n00b to DW and MySQL but have had many years in
    the IT industry
    Any ideas?
    [I have looked at the suggested in
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=189&threadid=1174350&hi ghlight_key=y&keyword1=tables
    but as you can see, I don't have any 'copy to' folder
    http://img188.imageshack.us/img188/7338/3lh4.jpg
    Thanks
    Ryan

    rick111 wrote:
    > This is how the connection is setup
    >
    http://img469.imageshack.us/img469/1408/1dy1.jpg
    > This proves I have tables
    http://img443.imageshack.us/img443/6436/2qp8.jpg
    The problem is almost certainly caused by the hyphen in your
    database
    name. Hyphens are illegal characters in SQL identifiers,
    unless
    "quoted". The MySQL standard for quoting is to use backticks
    around
    identifiers that use illegal characters. phpMyAdmin does this
    by
    default, which is why you're seeing everying in phpMyAdmin.
    Dreamweaver now also does it by default, but there was a
    version (I
    forget which) that didn't do it. You need to apply the
    appropriate
    updater to your version of Dreamweaver. Then go to the Site
    menu, click
    Advanced, and select Remove Connection Scripts. Open a
    Recordset or
    other database connected dialog box to generate the new
    connection
    scripts, which should display the missing tables.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • Problem with JBDC connection to mysql in tomcat

    hi ,
    can anyone plz help me?..
    iam new to JSP. iam trying to impelement a application in JSP with JDBC connection using tomcat. Database is MYSQL .
    iam getting the following error:
    org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction.
    Attempted reconnect 3 times. Giving up.)"
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         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
    javax.servlet.ServletException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction.
    Attempted reconnect 3 times. Giving up.)"
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.test_jsp._jspService(test_jsp.java:81)
         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:332)
         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)
    THIS IS MY APPLICATION:
    <html>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <sql:query var="rs" dataSource="jdbc/TestDB">
    select id, foo, bar from testdata
    </sql:query>
    <html>
    <head>
    <title>DB Test</title>
    </head>
    <body>
    <h2>Results</h2>
    <c:forEach var="row" items="${rs.rows}">
    Foo ${row.foo}
    Bar ${row.bar}
    </c:forEach>
    </body>
    </html>
    Following is the context file called "DBtest.xml" stored in webapps/DBtest/META-INF folder( i have a same copy of the file in /conf/Catelina/localhost)
    <Context path="/DBTest" docBase="DBTest"
    debug="5" reloadable="true" crossContext="true">
    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
    </Context>
    i have following web.xml file in webapps/DBtest/WEB-INF
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
    <description>MySQL Test App</description>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/TestDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    i have been refering to the internet form past 3 days and making lot of changes.but,there is no use.
    plz guide me
    thanks

    Perhaps a stupid question: is MySQL running and listening on port 3306? The problem is not always in the webapp. Perhaps you can create a small test class that uses Driver to make a connection to your database.

  • Connectivity with MySQL in Windows

    How can I connect JSP with MySQL in Windows?
              I Tried out the following code but It did not work
              Class.forName("org.gjt.mm.mysql.Driver");
              Connection cn = DriverManager.getConnection("jdbc:mysql:///test");
              

    I think you missed the IP address for your MySQL server machine.
              If it's on the same computer, try this:
              jdbc:mysql://localhost/test
              "John Jacob" <[email protected]> wrote in message
              news:[email protected]..
              > How can I connect JSP with MySQL in Windows?
              > I Tried out the following code but It did not work
              >
              > Class.forName("org.gjt.mm.mysql.Driver");
              > Connection cn = DriverManager.getConnection("jdbc:mysql:///test");
              

  • Jar file connection with mysql

    Hello everyone i ve a problem if you people could solve please help...
    When i compile my java code with mysql connection it works perfectly, but when i convert into jar file its not updating any values in the mysql database
    Can anyone tell me a solution.

    subhavenkatesh wrote:
    Can anyone tell me a solution.You have a bug. Find it. Fix it.

Maybe you are looking for

  • Multi-authoring with source control with RH10 and RH11

    Situation: Writer A is running RH10. Writer A opens Project A, from Visual Studio Source Control, which is connected to a Team Foundation Server. A new employee, Writer B, has been given RH11. Writer A can't install RH11 until after mid-June because

  • Ipod Video and Alpine CDE-9852 Problem.

    I'm having problems with my new Alpine CDE-9852, and my black 60 gig ipod Video (1.11 software verison). When I first pluged in my Ipod to the unit I got Error 01, my first thought was that I needed to install software on the ipod, but from reading t

  • Need to create a few objects....

    Hi! I need to create a few objects, but do not know how: create Shows in structure create User Exit create Enhancement for Z program create customer screen create OSS notes Bassically I need a t-code for each issue and a few steps that are to be done

  • Having Trouble With Formula

    i am doing an assignment and im having a lot of trouble with it. here is what it is asking for read a value representing a number of seconds, then print the equivalent amount of time as a combination of hours, minutes, and seconds. (For example, 9999

  • How to specify query timeout

    how to set query timeout in code so that if connection breaks then it can restart immediately help me out