JSP & MySQL

Hi!
I am Pranay. I want to connect my JSP with MySQL. Will you please help me? I want the detail-code and pre-coding instructions.....
General Informations:
1. JDK 1.5.0
2. Apache Tomcat 4.1
3. MySQL Server 5.0
4. MySQL Connector/J 5.0.4
5. JAVA_CLASSPATH
C:\Program Files\Java\jdk1.5.0\bin
6. CLASSPATH
C:\Program Files\mysql-connector-java-5.0.4
Plz consider that I have a table in my MySQL database name tab1 which has fields: name,roll,date_of_birth.
Thanx...

The error you are getting looks like a network (socket) error rather than a JDBC or MySQL problem. The error indicates that a connection cannot be negotiated from Tomcat to MySQL. Are you sure MySQL is running on your laptop? Try to telnet to the MySQL port:
(on windows, from the command prompt)
C:\>telnet localhost 3306
If this connects (the command promt screen should clear) then the problem is elsewhere, but my bet is you won't be able to connect this way either.
If you cannot connect using telnet:
1. Verify that MySQL is running on your laptop
2. Verify that it's listening on port 3306
3. Check that you don't have any local firewall apps blocking this traffic
4. Verify that you don't have any manual host configurations which mean "localhost" points somewhere else (unlikely)
If you CAN connect using telnet:
1. Verify that your connection string is correct as per the MySQL JDBC Driver documentation
2. Verify that your authentication credentials are correct (don't think it's this)
Now... for a few supplimentary notes:
You appear to be using the connection.isClosed() method to test whether you have a connection. This serves no purpose in the context you are using it as it's just a boolean which gets set when close() is called on the connection. ergo you could quite easily have a broken connection which returns "false" on an isClosed() call.
Also, it is (strictly speaking) considered a better architecture to limit your JSP code to "display logic" only. This means it is usually void of any business logic or database-related code. You should really look at something like the MVC architecture (model-view-controller). This will save you a lot of headaches in the long run. If nothing else, debugging JSPs can be a real nightmare. I recommend you look at the Struts project (Apache Jakarta). It has become the defacto standard implementation of MVC.
Good luck :)

Similar Messages

  • JSP + MYSQL question: input form value into a SQL table

    Hello,
    I am writing some JSP code to read input information from a input form to write this information into a SQL field.
    My problems are:
    - how can i pass the input form information to other jsp file ? (like Getproperty of something like this)
    - how can i move the content of any input information into a variable ? I mean something like this:
    String a1;
    username.value.of.the.input.field.in.forum_jsp = a1.in.addmessage_jsp;and then:
    int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " +  " usercode, " + " messagedate,  " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");------
    The SQL table looks like this:
    stmt.executeUpdate("CREATE TABLE forummessages (messagecode int AUTO_INCREMENT PRIMARY KEY, usercode int, messagedate date, message char(255) not null)");My codes are:
    forum.jsp - this one should pass the input information to addmessage.jsp
    <%@ page contentType="text/html; charset=iso-8859-2" %>
    <%@ page import="java.sql.*" %>
    <%
    Connection con = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String url =  "jdbc:mysql://localhost:3306/mysql";
      con =  DriverManager.getConnection(url,"root", "");
      stmt = con.createStatement();
      String sql = "SELECT * FROM forummessages,users,bmwecode WHERE (forummessages.usercode=users.usercode) AND (users.bmwcode=bmwecode.bmwcode)";
      ResultSet rs = stmt.executeQuery(sql);
    %>
    <html>
    <head>
    <title>JSP + MYSQL Teszt</title>
    </head>
    <body>
    <a href="forum.jsp">Forum / Uj hozzaszolas</a>
    <a href="userlist.jsp">Felhasznalok kilistazasa</a>
    <a href="adduser.jsp">Felhasznalo hozzadasa</a>
    <a href="deletemessage.jsp">Hozzaszolas torlese</a>
    <br><br>
    <form action="addmessage.jsp" method=post">
    Felhasznalo:
    <input type="text" name="username">
    <br><br>
    Hozzaszolas:
    <input type="text" name="message">
    <br><br>
    <input type="submit" value="Uj hozzaszolas">
    <br><br>
    <table border="0">
    <tr>
    <th>messagecode</th>
    <th>user</th>
    <th>car type</th>
    <th>message</th>
    </tr>
    <%
      while(rs.next()){
    %>
    <tr>
    <td><%=rs.getInt("messagecode") %></td>
    <td><%=rs.getString("username") %></td>
    <td><%=rs.getString("bmwtype") %></td>
    <td><%=rs.getString("message") %></td>
    </tr>
    <%
      } // end while
    %>
    </table>
    </body>
    </html>
    <%
    } catch (Exception e) {
      out.println("<font color=red><h3>Error:</h3></font>" + e);
      e.printStackTrace();
    } finally {
      try {
        if (stmt!=null) {
          stmt.close();
        if (con!=null) {
          con.close();
      } catch (Exception e) {
        e.printStackTrace();
    %> ----
    addmessage.jsp
    <%@ page contentType="text/html; charset=iso-8859-2" %>
    <%@ page import="java.sql.*" %>
    <%
    Connection con = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String url =  "jdbc:mysql://localhost:3306/mysql";
      con =  DriverManager.getConnection(url,"root", "");
      stmt = con.createStatement();
    int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " +  " usercode, " + " messagedate,  " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");
    } catch (Exception e) {
      out.println("<font color=red><h3>Hiba:</h3></font>" + e);
      e.printStackTrace();
    } finally {
      try {
        if (stmt!=null) {
          stmt.close();
        if (con!=null) {
          con.close();
      } catch (Exception e) {
        e.printStackTrace();
    %>
    <a href="forum.jsp">Forum / Uj hozzaszolas</a>
    <a href="userlist.jsp">Felhasznalok kilistazasa</a>
    <a href="adduser.jsp">Felhasznalo hozzadasa</a>
    <a href="deletemessage.jsp">Hozzaszolas torlese</a>
    <br><br>---
    Thank you for your help in advance.

    SELECT DISTINCT
    hou.name
    ,poh.segment1 po_num
    ,pol.line_num po_line_num
    ,poh.currency_code
    --,trunc(poh.creation_date) po_creation_date
    ,pol.cancel_flag
    ,msi.segment1 item_num
    ,pol.unit_price
    ,round(cost.item_cost,5)
    ,round((&p_rate * pol.unit_price),5) "CONVERSION"
    ,(cost.item_cost - round((&p_rate * pol.unit_price),5)) difference
    ,pov.vendor_name
    FROM
    po.po_headers_all poh
    ,po.po_lines_all pol
    ,po.po_vendors pov
    ,hr.hr_all_organization_units hou
    ,inv.mtl_system_items_b msi
    ,bom.cst_item_costs cost
    WHERE
    poh.po_header_id = pol.po_header_id
    and pov.vendor_id = poh.vendor_id
    and poh.org_id = hou.organization_id
    and hou.organization_id = :p_operating_unit
    and poh.currency_code = :p_currency
    and poh.creation_date between :po_creation_date_from and :po_creation_date_to
    and poh.type_lookup_code = 'BLANKET'
    and msi.inventory_item_id = pol.item_id
    and cost.INVENTORY_ITEM_ID = pol.ITEM_ID
    --and (cost.item_cost - pol.unit_price) <> 0
    and (cost.item_cost - round((&p_rate * pol.unit_price),5)) <> 0
    and cost.organization_id = 1
    and msi.organization_id = 1
    and cost.cost_type_id = 3 --- Pending cost type
    and nvl(upper (pol.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
    and nvl(upper (poh.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
    and nvl(pol.cancel_flag, 'N') = 'N'
    and &p_rate user parameter
    I want this p_rate to be passed as a user parameter.

  • JSP - MYSQL HELP

    HI,
    Im trying to create a JSP which connects to a mysql database.
    I have downloaded all the connectivity drivers and dont know what to do from this stage.
    I have heard people talking about tomcat and apache but was wondering if i need them?
    Im new to all this connectivity bit so this is why i need help!!
    If anyone has any good links to some good jsp/mysql tutorials, please share!!!
    Thanks a lot

    You need a servlet/JSP engine, to start. You can't write or deploy a JSP without a servlet/JSP engine. Apache Tomcat is a good one to start with. It's free and robust:
    http://jakarta.apache.org/tomcat
    Here's a tutorial to get you started with servlets/JSP:
    http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
    Do a Google search or look at the Sun tutorials if you want more. - MOD

  • JSP MYSQL ERROR moving in resultset

    Hi I am new to jsp & mysql .
    I am trying to fetch data in a multiple select list box in my jsp page from a table in mysql . It fetches the first value and then exception is generated as no data found while there is data in the table . The same data in the table is fetched when i fetch in a dynamic table . I observed that i am having problems in fetching data only in list box . Please help me. It is a part of my project.
    Thanks

    Hi
    The code was generated my macromedia dreamweaver but still i'll writing it below:
    <select name="select" size="1" multiple>
    <%
    while (Recordset1_hasData) {
    %>
    <option value="<%=((Recordset1.getObject("overridetype")!=null)?Recordset1.getObject("overridetype"):"")%>"><%=((Recordset1.getObject("overridetype")!=null)?Recordset1.getObject("overridetype"):"")%></option>
    <%
    Recordset1_hasData = Recordset1.next();
    Recordset1.close();
    Recordset1 = StatementRecordset1.executeQuery();
    Recordset1_hasData = Recordset1.next();
    Recordset1_isEmpty = !Recordset1_hasData;
    %>
    </select>

  • JSP/MYSQL Hosting

    Hey all,
    Im looking to host a JSP/MYSQL site. Please tell me a hosting provider. also are there any providers in India that you know of . would really help if tis the same country.
    after looking through a lot of sites i have shortlisted.
    http://www.eatj.com and http://4java.ca tell me if there is anything in the same budget range. Are there anybody who is availing these services. please give your comments on the same
    Thanks
    Ritesh

    google myjavaserver
    it's free, but slow and space limited...

  • I have setup JSP & MySQL but how can i Connect it to eche other ?

    I feel sory by asking this qustion but i tried very enough
    100 mile start from 1 mile ^_^
    I have tested JSP files by http://localhost:8080/test.jsp
    and it works very will
    also i have already installd MySQL and i can create databases and tables by http://localhost/phpMyAdmin
    so what i have to do else to connect JSP to MySQL ? , ( if nothing )
    how can i test that MySQL Connected with JSP, so that i can display data from database ?
    Best Regards
    JMalik

    create a java bean, which is just similar to a java class and put the database connection there so you wouldn't have to include that code in all you jsps everytime you connect to the database
    this is for DbConnection.java
    package connection;
    import java.sql.*;
    import java.io.*;
    public class DBConnection
         private Connection con;
         public DBConnection()
              try
                  Class.forName("com.mysql.jdbc.Driver");
                  con = DriverManager.getConnection("jdbc:mysql://localhost/yourfolder?user=yourusername&password=yourpassword");
            catch (Exception e)
                 e.printStackTrace();
         public Connection getConnection()
              return con;
         public void close()
              try
                   con.close();
              catch(Exception e)
                   e.printStackTrace();
    }in another bean/class which connects to your database,
    say for example this is SelectUsers.java
    public String[] selectActiveUsers(int id) throws Exception, SQLException
         try
                   con = new DBConnection().getConnection();
                   Statement stmt = con.createStatement();
                   String ins = "<your select statement>";     
                            stmt.executeUpdate(ins);
                            con.close();
                   stmt.close();
             catch (SQLException se)
                    System.out.println("SQL Exception: " + se.getMessage() + "not connected");
                    se.printStackTrace(System.out);
         }and in your jsp, instantiate the class
    users.jsp
    SelectUsers su = new SelectUsers();
    String[] users = su.selectActiveUsers(1);got it?
    Message was edited by:
    shuini

  • JSP + MySQL + Linux + Tomcat4.1 Chinese display problem

    Hello all!
    I have a problem to use JSP to display Chinese which is read from MySQL database. It works well under Windows XP. But when I move the code to Linux. The Chinese can't be displayed any more.
    The only way to display Chinese correctly is to remove <%@ page contentType="text/html; charset=Big5" %>. This requires to set the browser encoding manually every time, which is not what I want.
    I am not sure if I need store the Chinese as Big5 or other unicode in MySQL. Right now, I just insert it into database directly without specifying the characters set.
    I have been searching for solutions for quite a while and can't get the answer. Please help me to conquer this problem!
    Below is the simplified version of my code:
    <html>
    <head>
    <%@ page contentType="text/html; charset=Big5" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="ConnectionPool.*" %>
    <%@ page session="true" %>
    </head>
    <body>
    <table>                    
    <%
    ServletContext context = getServletContext();
    ConnectionPool connectionPool = (ConnectionPool)context.getAttribute("ConnectionPool");
    Connection connection = connectionPool.getConnection();
    Statement statement = connection.createStatement();
    String sqlCmd = "SELECT chinese_word FROM word";     
    String chinese_word;
    ResultSet rs = statement.executeQuery(sqlCmd);
    while (rs.next())
         chinese_word = rs.getString("chinese_word ");               
         out.println("<tr><td>" + chinese_word );
         out.println("</td></tr>");
    connectionPool.free(connection);
    %>
    </table>
    </body>
    </html>
    Thanks a bunch,
    Sophie

    hi
    i am india so no much command on chiness, but, as a solution process , i suggest this
    in jsp, response is the default object, so, whereever u want chiness char, use
    response.setContentType("text/html; charset=Big5");
    and again swith to normal english mode
    hope it proceeds...
    pranav

  • Problem: JSP, MySQL, UTF-8

    Hello!
    I use Netbeans 6.5, MySQL 5.0.67, Apache Tomcat 6.0.18, MySQL Connector J 5.1.6 to write simple web database application in JSP. Now I have problem with encoding of non-latin character strings returned from database.
    Database was created by query:
    CREATE DATABASE mydb DEFAULT CHARACTER SET = utf8Resource was defined in context.xml as follows:
        <Resource name="jdbc/ipdbDatasource"
            auth="Container"
            type="javax.sql.DataSource"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/ipdb_10?autoReconnect=true&characterSetResults=UTF-8"
            username="root"
            password=""
            maxActive="100"
            maxIdle="30"
            maxWait="10000"/>Test page source is:
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <sql:query var="rooms" dataSource="jdbc/ipdbDatasource" >
        SELECT address, descr FROM room
    </sql:query>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>&#1058;&#1077;&#1089;&#1090;&#1086;&#1074;&#1072;&#1103; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1072;</h1>
            <c:forEach var="room" items="${rooms.rows}">
                <p>${room.address}</p>
            </c:forEach>
        </body>
    </html>Page header <h1> content is OK, but ${room.address} appears in wrong encoding. What can cause this problem?

    I would suggest that you start by looking a jdbc only. JSP is not JDBC. XML is not JDBC.
    Moreover the ONLY way to determine what is actually being extracted from the database in a text value is to print the characters as integers. If you attempt to display them using ANYTHING (System.out, swing, xml, file io) then they will be mapped. And mapped data is not the same as what you got from the database.

  • [b][u]JSP/mySQL CREATE DATABASE problem[/u][/b]

    I am trying to create a mySQL DB through JSP program (query).
    The Query :
    stmt.executeUpdate("CREATE DATABASE employee;");
    is not working. PLEASE HELP ME.................
    The program is as follows.
    try
    Connection con =null;
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","");
    System.out.println("Connection Established");
    try {
    System.out.println("Entered Try Block");
    stmt=con.createStatement();
    stmt.executeUpdate("CREATE DATABASE employee;");
    System.out.println("Query Executed");
    catch(Exception e){ 
    System.out.println("Entered Catch Block");
    System.out.println("Query Skipped");
    catch (SQLException ex)
    while (ex != null){
    System.out.println("sql exception"+ex);
    ex = ex.getNextException ();
    Message was edited by:
    sam_john

    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","");
    Access denied for user: '[email protected]' (Using password: NO)
    You must provide a password for your connection.
    Your code should have been as follows:
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","YOUR_PASSWORD_HERE");Anyway, to create a database or a table in a db server like MySQL, you must have the good privileges to.
    Go to <MySQL_INSTALL_DIR>/Docs/ directory, you'll find there the MySQL manual.chm. Take a look at the the Tutorial section.
    In order to know how to use jdbc Connector/J, take a look at the documentation shipped with: /mysql-connector-java-X.X.X/docs/connector-j.html
    Here a typical code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    public class TestMySQL {
         public static void main(String[] args) {
              Connection con = null;
              Statement stmt = null;
              try {
                   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock", "Dude", "YOUR_PASSWORD_HERE");////// put the right password here
                   System.out.println("Connection Established");
                   System.out.println("Entered Try Block");
                   stmt = con.createStatement();
                   stmt.executeUpdate("CREATE DATABASE employee");
                   System.out.println("Query Executed");
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   if (stmt != null) {
                        try {
                             stmt.close();
                        } catch (Exception e) {
                   if (con != null) {
                        try {
                             con.close();
                        } catch (Exception e) {
    }Hope That Helps

  • JSP Mysql Connection Problem

    Hi Friend,
    I am facing some problem in connecting mysql with jsp .
    When I try and connect to mysql with the following connection string
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdhiraj?user=root&password=dh");
    Statement statement     = con.createStatement();
    I get an error :
    java.sql.SQLException: Communication link failure: Bad handshake
    I don't know what is wrong,
    as I had tested mysql using telnet and it connects and executes sql nicely.
    Waiting for ur reply,
    Dhiraj Agrawal
    mail to : [email protected]

    Hi,
    You need to make sure that , you have given correct database name, user id and password in the connection url. and also check the jdbc driver is loaded properly. If your mysql is running in the standard port, you need not give the port as 3306.
    Here is the example :
    import java.sql.*;
         Notice, do not import org.gjt.mm.mysql.*
    or you will have problems!
    public class XampleClass
    public static void main(String[] Args)
    try {      
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    catch (Exception e) {
    System.err.println("exception while loading
    driver.");
    e.printStackTrace();
    try {
    Connection C = DriverManager.getConnection(
    "jdbc:mysql://localhost/test?user=myuser&password=mypwddb");
    // Do something with the Connection
    catch (SQLException e) {
    System.out.println("Exception: " + e);
    This is the format for conenction url :
    jdbc:mysql://[hostname][:port]/dbname[?param1=value1][&param2=value2]...
    Hope this helps you.
    Thanks,
    Senthil_Slash

  • JDBC/JSP/MySQL Code works from my local machine, but not on server

    Hi there!
    I've been struggling with this problem for a while.
    I have a database from which I need to read and display some data on a browser. (The database is set up for remote access).
    I'm using the following JSP/JDBC code to do that.
    Class.forName ("com.mysql.jdbc.Driver").newInstance();
    out.println("<BR> Connecting to DB...Pls. Wait <BR>");
    Connection con = DriverManager.getConnection("url","user","pwd");
    if(con.isClosed())
    out.println("<BR><BR><BR>" +"Could NOT connect to MySQL Database...");
    else out.println("<BR> CONNECTED !!! <BR>");
    Statement stmt = con.createStatement();
    results = stmt.executeQuery("SELECT * FROM TableName" );
    When I run this of my local machine, it works fine. But when I upload it to a server, it doesn't run through. I dont get either the connected or not connected message.
    I tried this piece of code that I found online to check the driver.
    /*Driver d = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
    out.println("<BR>Got a driver instance. ");
    if (d.acceptsURL(url)) out.println("<BR>The driver does accept my URL");
    else out.println("<BR>The driver doesn't like the URL I'm trying"); */
    I ran it off the server and it worked. I got the outputs --Got a driver instance and The driver does accept my URL
    I'm unable to figure out why this code can be run locally from my machine, but not from a different location. The database is NOT on my machine.
    Any inouts will be really appreciated.
    I'm using an Apache Tomcat container and the database is MySQL.

    Just wanted to mention
    The database is on another (3rd) machine.
    So I have
    1. My local machine
    2. Database hosted on a 2nd machine
    3. Place I'm moving my code to (its basically a hosting account provided by an external company)
    I can access the database from my local machine. However, when I move the code over to another machine, it doesn't work.

  • JSP - MySQL - MS Access

    I have a set of tables in MS Access database and MySQL database.
    My jsp application is running with the help of Apache/Tomcat in Linux box.
    I've the MM.MySQL Driver to integrate MySQL with my application.
    my problem is to know how to communicate jsp with MS Access here.
    I don't know how to connect jsp to MS Access in Linux.
    I searched for solution and finally got an idea of using MyODBC api.
    I need to import data from MS Access to MySQL using MyODBC on Linux.
    Can anyone help me on how to install,configure MyODBC and import data.
    or please pass any reference url.
    or
    please suggest me any solution for this.
    Thanks
    Senthil

    Thats what I meant. If both (Access and MySQL) both run on Windows there should be no problem. But if MySQL is on Linux and Access is on Windows it could be.
    How about setting up Mysql on Windows, going the way magnoli supposed and after that using mysqldump to export zo linux.

  • Jsp mysql database connectivity

    Hello there,
    I am trying to connect to mysql.
    I have downloaded the mysql driver from mysql.com and placed it in
    "C:\j2sdk1.4.2\Tomcat 4.1\common\lib".
    My code is
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=username&password=password");
    // Replace db_name with your own and the parameter values of your own
    Statement stmt = Conn.createStatement();
    ResultSet RS = stmt.executeQuery("SELECT style FROM new_artist");
    String result = null
    while(RS.next()){
    result = RS.getString(1);
    %>
    <%= result %>
    But...
    It is throwing error,
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 0 in the jsp file: /dbex.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\j2sdk1.4.2\Tomcat 4.1\work\Standalone\localhost\_\dbex_jsp.java:52: ';' expected
    ^
    1 error
         at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
         at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
         at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
         at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    Could anyone tell me the reason??
    Please help..
    Thanx in advance..

    <code>
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=username&password=password");
    // Replace db_name with your own and the parameter values of your own
    Statement stmt = Conn.createStatement();
    ResultSet RS = stmt.executeQuery("SELECT style FROM new_artist");
    String result = null
    while(RS.next()){
    result = RS.getString(1);
    %>
    <%= result %>
    </code>
    You forget the ; at the end of: String result = null

  • Handshaking Problem ( JSP & MySql )

    Dear All
    I am facing the foolowing problem with mysql and servlet:
    exception
    javax.servlet.ServletException: Communication failure during handshake. Is there a server running on localhost:3306?
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
         org.apache.jsp.jobcard16_jsp._jspService(org.apache.jsp.jobcard16_jsp:1599)
         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)
    root cause
    java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
         com.mysql.jdbc.MysqlIO.init(MysqlIO.java:619)
         com.mysql.jdbc.Connection.createNewIO(Connection.java:1605)
         com.mysql.jdbc.Connection.connectionInit(Connection.java:1056)
         com.mysql.jdbc.Driver.connect(Driver.java:297)
         java.sql.DriverManager.getConnection(Unknown Source)
         java.sql.DriverManager.getConnection(Unknown Source)
         org.apache.jsp.jobcard16_jsp._jspService(org.apache.jsp.jobcard16_jsp:88)
         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)

    nikhil_p_chavan wrote:
    Yes, there is MySql running on 3306.The exception says it is not. This can have the following (logical) causes:
    1) MySQL is actually not running on 3306.
    2) MySQL does not allow connections.
    3) Some firewall software is blocking MySQL.
    4) Some firewall software is blocking port 3306.
    And in the future please don't mark the topic as answered while your actual problem is not solved. I was under the impression that it was answered right after my first reply and when you confirmed that there was no MySQL server at post 3306.

  • Couldnt solve/explain this jsp/mysql error

    in one of my page that makes the table i have these codes :
         String a = "CREATE TABLE inv"+invId+" (";
         String b = "itemId int(5) NOT NULL, ";
         String c = "itemSerial varchar(255), ";
         String d = "itemAsset varchar(255), ";
         String e = "itemComments varchar(255), ";
         String f = "itemModel int(5) NOT NULL, ";
         String g = "itemStatus int(5) NOT NULL, ";
         String h = "itemEnterDate date NOT NULL, ";
         String i = "PRIMARY KEY (itemId))";
         String makeTB = a+b+c+d+e+f+g+h+i;
         SQLStatement3.executeQuery(makeTB);
    then the other processing page is suppose to delete it :
    String prefixId = request.getParameter("objectId");
    String confirmId = request.getParameter("confirmId");
    if (prefixId == null) {
         out.println("prefixId == null");
    else if (confirmId == null) {
         out.println("confirmId == null");
    else {
         String delPrefix = "Delete from itemPrefix where prefixId="+prefixId;
         SQLStatement.executeQuery(delPrefix);
         String dropTB = "Drop table inv"+prefixId;
         SQLStatement.executeQuery(dropTB);
         response.sendRedirect("invConfirm.jsp?object="+confirmId+"&msg= has being deleted.&url=invAddPrefix.jsp");
    the problem is when i created the table
    i checked it, and it exist so theres no problem there
    but when i attempt to delete it thru running the jsp page,
    i got this :
    javax.servlet.ServletException: General error: Unknown table 'inv8'
    before dropping the table i did a "select * from inv8" in the query of mysql and it exist
    however got that msg when i try to drop that table thru jsp
    (that message usually appear when the table doesnt exist only)
    wierd thing is even when this error appears that table is dropped successfully too
    i dont know wads causing that error to pop up
    can anyone help me ?

    Don't know if this will help but when executing DDL statements (create, drop, alter) and DML statements (insert, update, delete) you should use executeUpdate() instead of executeQuery().

Maybe you are looking for

  • Hyperlinks not Printing

    Well, not sure if this falls under here of Printed Documentation. So bear with me if I've posted this in the wrong place. Here's the problem: The helpfile HTML has created perfectly, and one page is a list of links to PDF files which the Users can co

  • IOS 6, Bluetooth, and iPhone 4

    When I originally purchased my iPhone 4, it did not properly pair via Bluetooth with my 2008 Infiniti FX 35 for hands-free calling.  It wouldn't maintain a connection.  Now with the iOS 6 update, the phone seems to pair with the car and maintain the

  • Calling  Report in   Customized Method   Created in  ZBUS2081

    Hi , I have created ZBUS2081  in that I  have  create one Customized  method  ZEMAIL  . now  in SE38   i have  wriiten  logic  to send  email to  person   . I want to use  this  report in ZEMIL   method   .   even I  used that  report  by  using   SU

  • Finder continually opens a window on its own...

    Hi Everyone, I'm just curious to see if anyone has seen the problem I've been experiencing. Literally every 2 minutes, the "Finder" opens the "My Computer" window. It doesn't matter what program I'm working on, the Finder immediately comes to the for

  • Phone Recommendations Needed!

    Hey everyone, So, I'm looking for a new phone! I've got a Nokia 3330 which though long-wearing is starting to look super dated. I'm basically looking for advice from anyone here - I need any recommendations to have the following features; 1) Works wi