Java JDBC:连接到远程mySQL数据库?
我尝试了此代码,但它给出了:Java JDBC:连接到远程mySQL数据库?,java,mysql,jdbc,phpmyadmin,Java,Mysql,Jdbc,Phpmyadmin,我尝试了此代码,但它给出了: 线程“main”java.sql.SQLException中出现异常:null,来自服务器的消息:“主机‘mobile-130-126-255-40.near.illinois.edu’不允许连接到此MySQL服务器” 我在谷歌上搜索了一下,似乎我必须授予数据库特权,但我不知道我的MySQL命令提示符在哪里。有没有办法在phpMyAdmin中授予特权?如有任何帮助,将不胜感激 点击windows+r 然后在其中键入“cmd”,然后按enter键。。这将打开wind
线程“main”java.sql.SQLException中出现异常:null,来自服务器的消息:“主机‘mobile-130-126-255-40.near.illinois.edu’不允许连接到此MySQL服务器”
我在谷歌上搜索了一下,似乎我必须授予数据库特权,但我不知道我的MySQL命令提示符在哪里。有没有办法在phpMyAdmin中授予特权?
如有任何帮助,将不胜感激 点击windows+r 然后在其中键入“cmd”,然后按enter键。。这将打开windows的命令提示符 那就去吧。。 mysql-u用户名-p按回车键 然后键入密码 i、 e 第1行:mysql-u root-h localhost-p 第2行:管理员 其中“admin”是您的密码 然后 mysql>将数据库名。*上的所有内容授予cmsuser@localhost由“密码”标识 点击windows+r 然后在其中键入“cmd”,然后按enter键。。这将打开windows的命令提示符 那就去吧。。 mysql-u用户名-p按回车键 然后键入密码 i、 e 第1行:mysql-u root-h localhost-p 第2行:管理员 其中“admin”是您的密码 然后
mysql>将数据库名。*上的所有内容授予cmsuser@localhost由“密码”标识 打开命令行控制台并从那里执行操作。
在u505743489_db.*上授予使用权限到'u505743489_db'@'mobile-130-126-255-40.near.illinois.edu'由'password'标识。
。在phpMyAdmin中,您可以在主选项卡或主数据库选项卡下授予权限(抱歉,我记不得了,但它就在那里).@BoristheSpider这可能是一个答案。@SotiriosDelimanolis我在哪里可以打开命令行控制台?打开命令行控制台并从那里开始操作。GRANT USAGE ON u505743489_db.*到'u505743489_db'@'mobile-130-126-255-40。near.illinois.edu'由'password'标识。
。在phpMyAdmin中,您可以在主选项卡中授予特权,或者在“主数据库”选项卡下(对不起,我记不起来了,但它就在那里)。@BoristheSpider这可能是答案。@SotiriosDelimanolis在哪里可以打开命令行控制台?
public void readDataBase() throws Exception {
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://185.28.21.11/u505743489_db?"+ "user=u505743489_db&password=password");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement
.executeQuery("select * from FEEDBACK.COMMENTS");
writeResultSet(resultSet);
// PreparedStatements can use variables and are more efficient
preparedStatement = connect
.prepareStatement("insert into FEEDBACK.COMMENTS values (default, ?, ?, ?, ? , ?, ?)");
// "myuser, webpage, datum, summary, COMMENTS from FEEDBACK.COMMENTS");
// Parameters start with 1
preparedStatement.setString(1, "Test");
preparedStatement.setString(2, "TestEmail");
preparedStatement.setString(3, "TestWebpage");
preparedStatement.setDate(4, new java.sql.Date(2009, 12, 11));
preparedStatement.setString(5, "TestSummary");
preparedStatement.setString(6, "TestComment");
preparedStatement.executeUpdate();
preparedStatement = connect
.prepareStatement("SELECT myuser, webpage, datum, summary, COMMENTS from FEEDBACK.COMMENTS");
resultSet = preparedStatement.executeQuery();
writeResultSet(resultSet);
// Remove again the insert comment
preparedStatement = connect
.prepareStatement("delete from FEEDBACK.COMMENTS where myuser= ? ; ");
preparedStatement.setString(1, "Test");
preparedStatement.executeUpdate();
resultSet = statement
.executeQuery("select * from FEEDBACK.COMMENTS");
writeMetaData(resultSet);
} catch (Exception e) {
throw e;
} finally {
close();
}
}