Results 1 to 3 of 3
  1. #1
    sophanith is offline Member
    Join Date
    Jul 2015
    Posts
    1
    Rep Power
    0

    Question cant connect to wamp MySQL via tomcat

    Hi everyone,
    I am trying to connect to MySql of wamp via tomcat but it is always fail.
    It would always give me exception on Connection conn line:
    "Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."

    Here is my code:
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:81/ebookshop", "root", "");

    Statement stmt = conn.createStatement();
    String sqlStr = "SELECT * from books WHERE author IN (";
    sqlStr += "'" + authors[0] + "'";
    for (int i = 1; i < authors.length; i++) {
    sqlStr += ", '" + authors[i] + "'";
    }
    sqlStr += ") AND qty > 0 ORDER BY author ASC, title ASC";

    System.out.println("Query statement is " + sqlStr);
    ResultSet rset = stmt.executeQuery(sqlStr);
    %>

    please help. Thanks in advance.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: cant connect to wamp MySQL via tomcat

    I can't really imagine the database server is listening on port 81.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: cant connect to wamp MySQL via tomcat

    Default MySQL port: 3306
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 4
    Last Post: 03-04-2012, 11:26 PM
  2. Cannot connect https using tomcat (keytool) gives an error 500
    By aditya_22cent in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-13-2011, 02:55 PM
  3. WAMP Server TOMCAT PROBLEM?
    By chathura87 in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2011, 03:03 PM
  4. connect servlet and jsp in tomcat
    By abcdef in forum Java Servlet
    Replies: 1
    Last Post: 02-18-2011, 12:04 PM
  5. Can NOT connect to Mysql
    By zed420 in forum New To Java
    Replies: 3
    Last Post: 12-18-2009, 08:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •