<%@ page import="java.sql.*"%>
<%
  Connection  con=null;
  Statement  st=null;
  ResultSet  rs=null;
  try {
       Class.forName("org.gjt.mm.mysql.Driver");
       con=java.sql.DriverManager.getConnection("jdbc:mysql://10.10.1.129:3306/test","root","123456");
       st=con.createStatement();
       rs=st.executeQuery("select * from t_test");
       out.print("<br>id------name------address<br>共有");
       int id;
       String name=null;
       String address=null;
       while(rs.next()){
         id = rs.getInt(1);
         name = rs.getString(2);
         address = rs.getString(3);
         out.println("<br>");
         out.print(id);
         out.println("------"+name+"------"+address);
       }
       rs.close();
       st.close();
       con.close();
      }
      catch(Exception ex)
      {
        out.println(ex.getMessage());
      }
%>

解决方案 »

  1.   

    异常:当运行 DateTest 时屏幕提示 “Server configuration denies access to data source”解决方法:首先进入 mysql 并以 root 登陆,随后输入如下内容。
    mysql> GRANT ALL PRIVILEGES ON [dbname].* to '[user]'@'[hostname]' 
      identified by '[password]';
     (注意:这里将 dbname 替换成你的数据库名称,在 DateTest 中是 test;将 user 替换成你的用户名,笔者的是 root;将 hostname 替换成 java 程序运行时所在的机器,笔者是在本机运行,即为'localhost';将 password 替换成你mysql中用户的密码,笔者的没有密码,即为''。)
      

  2.   

    顺便提交一下faq,这个问题好象还挺典型的
      

  3.   

    我是用在本机用tomcat来做web server的
      

  4.   

    我以前也有这种问题,而且还不是本机,一下就搞定了
    楼主有没有装mysql的后台界面?
      

  5.   

    GRANT ALL PRIVILEGES ON test.* to 'root'@'localhost' identified by '123456';
      

  6.   

    那你进mysql看看呢
    进mysql数据库
    SELECT * FROM db WHERE 1 LIMIT 0, 30
      

  7.   

    里面存储了哪些可以访问,哪些不可以
    編輯  刪除  172.16.58.178 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.113 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.151 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.160 ktfjoyme root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.71 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.17 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.14 haweather root Y Y Y Y Y Y N Y Y Y 
    編輯  刪除  172.16.58.100 ktfjoyme root Y Y Y Y Y Y N 这是我数据库里的信息
      

  8.   

    | Host      | Db      | User | Select_priv | Insert_priv | Update_priv | Delete_
    priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alt
    er_priv |
    +-----------+---------+------+-------------+-------------+-------------+--------
    -----+-------------+-----------+------------+-----------------+------------+----
    --------+
    | %         | test    |      | Y           | Y           | Y           | Y      
         | Y           | Y         | N          | Y               | Y          | Y  
            |
    | %         | test\_% |      | Y           | Y           | Y           | Y      
         | Y           | Y         | N          | Y               | Y          | Y  
            |
    | localhost | test    | root | Y           | Y           | Y           | Y      
         | Y           | Y         | N          | Y               | Y          | Y  
            |
    +-----------+---------+------+-------------+-------------+-------------+--------
    -----+-------------+-----------+------------+-----------------+------------+----
    --------+
    3 rows in set (0.01 sec)
      

  9.   

    根据此信息,你好象是应该可以了的啊
    localhost | test    | root | Y           | Y           
    再试一下呢?
      

  10.   

    你可以找一个windows的机子,装个odbc for mysql来试一下
    看一下可以不可以连
      

  11.   

    SELECT * FROM user WHERE 1 LIMIT 0, 30 
    user里面也应该有信息吧,不过为了保险,你还是看一下
      

  12.   

    mysql> select * from user where 1 limit 0,30;
    +-----------+------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
    | Host      | User | Password         | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
    +-----------+------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
    | localhost | root | 565491d704013245 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          |
    | localhost |      |                  | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          |
    +-----------+------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
    2 rows in set (0.00 sec)
      

  13.   

    localhost | root | 565491d704013245 | Y           
    种种迹象都表明你能访问啊
    对了你重起了吗?实现不行
    GRANT ALL PRIVILEGES ON test.* to 'root'@'127.0.0.1' identified by '123456';GRANT ALL PRIVILEGES ON test.* to 'root'@'本机ip' identified by '123456';
      

  14.   

    不知道是不是你机子localhost不能解吸
      

  15.   

    我明白了我用了IP地址,而不是localhost,谢谢 hotenM(可以包含中文字符) ,给分