- 论坛徽章:
- 0
|
这是我的代码:
- import java.sql.*;
- public class SampleIntro
- {
- public static void main(String[] args)
- {
- try
- {
- Connection conn;
- Statement stmt;
- ResultSet res;
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","test", "test");
- stmt = conn.createStatement();
- res = stmt.executeQuery("select * from test");
- while (res.next())
- {
- String name = res.getString("test");
- System.out.println(name);
- }
- res.close();
- }
- catch (Exception ex)
- {
- System.out.println("Error : " + ex.toString());
- }
- }
- }
复制代码
当我javac SampleIntro.java没有出错
但是java SampleIntro却出现以下提示
- Error : java.sql.SQLException: null, message from server: "#HY000Host 'jspServer' is not allowed to connect to this MySQL server"
复制代码
很奇怪,居然说我本地不允许访问mysql?可以啊!
我新建立的test用户和系统的root权限一样啊,Hosts都是localhost啊!
这个我都是可以运行成功的
- mysql -utest -ptest -Dtest
复制代码
[ 本帖最后由 lbersl 于 2006-8-4 08:38 编辑 ] |
|