<%@ 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());
}
%>
<%
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());
}
%>
mysql> GRANT ALL PRIVILEGES ON [dbname].* to '[user]'@'[hostname]'
identified by '[password]';
(注意:这里将 dbname 替换成你的数据库名称,在 DateTest 中是 test;将 user 替换成你的用户名,笔者的是 root;将 hostname 替换成 java 程序运行时所在的机器,笔者是在本机运行,即为'localhost';将 password 替换成你mysql中用户的密码,笔者的没有密码,即为''。)
楼主有没有装mysql的后台界面?
进mysql数据库
SELECT * FROM db WHERE 1 LIMIT 0, 30
編輯 刪除 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 这是我数据库里的信息
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)
localhost | test | root | Y | Y
再试一下呢?
看一下可以不可以连
user里面也应该有信息吧,不过为了保险,你还是看一下
+-----------+------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
| 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)
种种迹象都表明你能访问啊
对了你重起了吗?实现不行
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';