解决方案 »

  1.   

    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
    //myDB为数据库名
    Connection conn= DriverManager.getConnection(url);
      

  2.   

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/表名","用户名","密码");
      

  3.   

    public Connection getConn()
    {
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://localhost/数据库名?user=用户名&password=密码");
    }catch(Exception e)
    {
    e.printStackTrace();
    }
    return conn;
    }别忘了导如MySql驱动包
      

  4.   

    An error occurred at line: 1 in the jsp file: /liuyan/Conn.jsp
    Syntax error, insert ";" to complete Statement
    1: <%!
    2: Connection con = null;
    3: Statement stmt = null;
    4: ResultSet rs = null;
    An error occurred at line: 1 in the jsp file: /liuyan/Conn.jsp
    String literal is not properly closed by a double-quote
    1: <%!
    2: Connection con = null;
    3: Statement stmt = null;
    4: ResultSet rs = null;
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)