标题:jsp连接 mysql问题
只看楼主
jsjxjb2000
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-2-22
 问题点数:0 回复次数:1 
jsp连接 mysql问题
javax.servlet.ServletException: Communication failure during handshake. Is there a server running on localhost:3306?

我得mysql已经启动为什么总提示上面的问题。问题出在哪里呢??请各位大侠帮忙。
搜索更多相关主题的帖子: mysql jsp 
2005-02-22 10:53
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
得分:0 
jsp连接Mysql数据库
<%@ page contentType="text/html;charset=gb2312"%>
<% @page import="java.sql.*"
         import="java.util.*"
         import="*"%>
<% Connection conn;
   ResultSet rs;
   String sql="SELECT * FROM test";
   Statement stmt;
   try{
   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
   conn=DriverManager.getConnection("jdbc:mysql://localhost/test");
   stmt=conn.createStatement();
   rs=stmt.executeQuery(sql);
   outTable(rs,out);
  }
 catch(Exception e){
        e.printStackTrace(out);
        }
 finally{
      try{
         if(rs!=null)  rs.close();
         if(stmt!=null) stmt.close();
         if(conn!=null) conn.close();
         }
         catch(Exception e){}
         }
  private void outTable(ResultSet rs,PrintWriter out) throw Exception{
       out.println("<center><table border='2'>");
        ResultSetMetaData rsmd=rs.getMetaData();
        int colCount=rsmd.getColumnCount();%>
       <tr>
           <%for(int i=0;i<colCount;i++){%>
                 <th><%=rsmd.getColumnLabel(i+1)%><th>
                    <%}%>
   </tr>
     <%while(rs.next()){%>
               <tr>
               <%for(int i=0;i<colCount;i++){
                     %>
               <td><%=rs.getString(i+1)%></td>
               <%}%>
        </tr>
         <%}%>
          </table></center>
<%}
%>
2005-02-28 09:35



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




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

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