本帖最后由 Big_Wang5 于 2013-07-10 20:30:22 编辑

解决方案 »

  1.   

    你的web应用与MySQL是在一台服务器上吗
    另外,检查一下访问MySQL的用户是否有足够的权限
      

  2.   

    你mysql服务器太忙了,没空闲连接?或者是mysql服务器挂掉了!
      

  3.   

    本机的,我的wordpress使用的也是mysql就没有问题。
      

  4.   

    只是为了测试一下jdbc写的代码:import java.sql.*;
    import java.util.*;
    import java.lang.reflect.*;
    public class SqlConn{
    public static void main(String args[]){
    Statement stmt = null;
    Connection cn = null;
    String sql; try{
    Class.forName("com.mysql.jdbc.Driver");
    } catch(ClassNotFoundException ex){
    System.out.println("Not find  the  Driver!");
    } try{
    String urls="jdbc:mysql://localhost:3306/wordpress";
    String user="root";
    String password="xxxxxxxxx";
    cn= DriverManager.getConnection(urls,user,password);
     
    stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    sql="select  top 10 * from  wp_posts";
    ResultSet rs= stmt.executeQuery(sql);
        while(rs.next()){
             System.out.println(rs.getString(2)+"       "+rs.getString(3));
        }
        stmt.close();
        cn.close();
    }catch(SQLException e){
         e.printStackTrace();
    } } 
    }
      

  5.   

    这个程序没有太大的问题,就你的查询语句不对和下面的输出有对应。如果还不好那么加载一下驱动。方法如下:就是加载JAR 包, 在你的工程文件夹上点右键,最下面一个  
    properties(首选项), 在里面有个
     java build path 应该是左边第3个,然后 在右边选第2个,Add External JARs,然后选择你的数据库驱动程序(其实就是个JAR包),确定就可以了。