cannot connect to mysql with jsp??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hkma08
    New Member
    • Mar 2008
    • 11

    cannot connect to mysql with jsp??

    I dont know I should post JSP error in here or not. If not please redirect me to another one. Thx.

    I just installed apache tomcat with mysql with java, but i got error when try to connect to mysql database, what is happening? Here is my error msg:

    org.apache.jasp er.JasperExcept ion: Unable to compile class for JSP:

    An error occurred at line: 3 in the jsp file: /tutorial/test.jsp
    Syntax error on tokens, delete these tokens
    [code=java]
    <%@ page import="java.sq l.*" %>
    <%
    String connectionURL = "jdbc:mysql ://localhost:3306/test?username=" admin1"&passwor d="admin"";
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    [/code]


    Stacktrace:
    Code:
    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:308)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:273)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    Last edited by Atli; May 6 '08, 05:28 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Your problem is most likely in the connection string, where you put double quotes inside a double-quoted string.

    Try escaping the quotes inside the string using the \ char.
    Like:
    [code=java]
    // Instead of doing
    String myString = "user="username "etc..";

    // Try this
    String myString = "user=\"usernam e\"etc..";
    [/code]

    And btw, I moved the thread over to the Java forums. ;)

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Use the + operator to concatenate two Strings.

      Comment

      Working...