标题:JAVA 连接MySql出错
只看楼主
zacom
Rank: 2
等 级:论坛游民
威 望:2
帖 子:381
专家分:15
注 册:2007-9-15
结帖率:88.89%
已结贴  问题点数:20 回复次数:6 
JAVA 连接MySql出错
<%@ page contentType="text/html;l anguage=gb2312"  language="java" import="java.sql.*"%>
<html>
<body>
以下是从MYSQL数据库读取的数据:<br>
<table border=1>
<tr><td>id</td><td>书名</td></tr>
<%
     Class.forName("org.gjt.mm.mysql.Driver").newInstance();
     Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/jspdev","root","root");
     Statement stmt=con.createStatement();
     ResultSet rst=stmt.executeQuery("select * from book");
     while(rst.next())
    {
    out.println("<tr>");
    out.println("<td>“+rst.getString(1)+"</td>");
    out.println("<td>"+rst.getString(2)+"</td>");
    out.println("</tr>")
    }
    rst.close();
    stmt.close();
   con.close();
%>
</table>
</body>
</html>


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 7 in the jsp file: /testMysql.jsp
Syntax error on token "/", delete this token
4: 以下是从MYSQL数据库读取的数据:<br>
5: <table border=1>
6: <tr><td>id</td><td>书名</td></tr>
7: <%
8:      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
9:      Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/jspdev","root","root");
10:      Statement stmt=con.createStatement();


An error occurred at line: 7 in the jsp file: /testMysql.jsp
String literal is not properly closed by a double-quote
4: 以下是从MYSQL数据库读取的数据:<br>
5: <table border=1>
6: <tr><td>id</td><td>书名</td></tr>
7: <%
8:      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
9:      Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/jspdev","root","root");
10:      Statement stmt=con.createStatement();


An error occurred at line: 7 in the jsp file: /testMysql.jsp
Syntax error, insert ")" to complete Expression
4: 以下是从MYSQL数据库读取的数据:<br>
5: <table border=1>
6: <tr><td>id</td><td>书名</td></tr>
7: <%
8:      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
9:      Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/jspdev","root","root");
10:      Statement stmt=con.createStatement();


An error occurred at line: 16 in the jsp file: /testMysql.jsp
Syntax error, insert ";" to complete Statement
13:     {
14:     out.println("<tr>");
15:     out.println("<td>“+rst.getString(1)+"</td>");
16:     out.println("<td>"+rst.getString(2)+"</td>");
17:     out.println("</tr>")
18:     }
19:     rst.close();
搜索更多相关主题的帖子: JAVA MySql 
2009-09-29 18:47
elan1986
Rank: 6Rank: 6
等 级:贵宾
威 望:18
帖 子:458
专家分:407
注 册:2007-12-17
得分:4 
为什么要写成那样那个的servlet呢??
不如直接写个方法 然后调用
2009-09-29 22:53
柠檬可乐
Rank: 4
等 级:业余侠客
威 望:6
帖 子:66
专家分:205
注 册:2009-6-16
得分:4 
你试一下:
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url="jdbc:mysql://localhost:3306/JavaWeb?useUnicode=true&characterEncoding=gb2312";
connection con=DriverManager.getConnection(url,"root","root");
Statement stmt=con.createStatement();

第十七行少了分号
2009-09-29 23:18
zacom
Rank: 2
等 级:论坛游民
威 望:2
帖 子:381
专家分:15
注 册:2007-9-15
得分:0 
现在是连接不上的问题。不要说方法好不

没有最好只有更好
2009-09-30 12:04
pywepe
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:296
专家分:483
注 册:2009-4-5
得分:4 
回复 楼主 zacom
看我这个


//1、MySQL数据库
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);

java群
62635216
欢迎加入
2009-09-30 12:46
passhugh
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-10-8
得分:0 
3306的端口
2009-10-08 13:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-287271-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108532 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved