日期:2014-05-18  浏览次数:20811 次

请各位帮忙看看我的jsp连接mysql哪里出了问题拉
故障:JSP连不上MYSQL数据库!!
配置:
JDK5.0.11   +   tomcat6.0   +   mysql5.0   分别测试安装成功,运行.

然后下载驱动mm.mysql,(这个解释一下,没有用最新那个什么驱动是因为我做的毕业设计上是用这个驱动).然后解压出一个文件org\gjt\mm\mysql,放到这个路径C:\Tomcat   6.0\webapps\ROOT\WEB-INF\classes\org\gjt\mm\mysql

测试代码:
<%@   page   contentType= "text/html;charset=gb22 "   %>
<%@   page   import= "java.sql.* "   %>
<html>
<body>
<%  
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
String   url= "jdbc:mysql://localhost/bookstore?user=depthman& "+ "password=depthman&useUnicode=true;characterEncoding=8859_1 "
//depthman是mysql的用户名,密码也是depthman,我不知道这一句写的对不对!?
bookstore是已经存在的数据库.
Connection   conn=DriverManager.getConnection(url);
Statement   stmt=conn.createStatement();
String   sql= "select   *   from   bookstore; ";
ResultSet   rs=stmt.executeQuery(sql);
while(rs.next()){%>
第一个字段内容为: <%   =rs.getString(1)   %>
第二个字段内容为: <%   =rs.getString(2)   %>
<%}%>
<%   out.print( "数据库操作成功,恭喜你!!! ");   %>
rs.close();
stmt.close();
conn.close();
%>

</body>
</html>

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

An   error   occurred   at   line:   7   in   the   jsp   file:   /test.jsp
Syntax   error,   insert   "; "   to   complete   LocalVariableDeclarationStatement
4:   <body>
5:   <%  
6:   Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
7:   String   url= "jdbc:mysql://localhost/bookstore?user=depthman& "+ "password=depthman&useUnicode=true;characterEncoding=8859_1 "
8:   Connection   conn=DriverManager.getConnection(url);
9:   Statement   stmt=conn.createStatement();
10:   String   sql= "select   *   from   bookstore; ";


An   error   occurred   at   line:   13   in   the   jsp   file:   /test.jsp
Syntax   error   on   token   "= ",   @   expected
10:   String   sql= "select   *   from   bookstore; ";
11:   ResultSet   rs=stmt.executeQuery(sql);
12:   while(rs.next()){%>
13:   第一个字段内容为: <%   =rs.getString(1)   %>
14:   第二个字段内容为: <%   =rs.getString(2)   %>
15:   <%}%>
16:   <%   out.print( "数据库操作成功,恭喜你!!! ");   %>


An   error   occurred   at   line:   13   in   the   jsp   file:   /test.jsp
Syntax   error   on   token(s),   misplaced   construct(s)
10:   String   sql= "select   *   from   bookstore; ";
11:   ResultSet   rs=stmt.executeQuery(sql);
12:   while(rs.next()){%>
13:   第一个字段内容为: <%   =rs.getString(1)   %>
14:   第二个字段内容为: <%   =rs.getString(2)   %>
15:   <%}%>
16:   <%   out.print( &quo