import java.sql.*;public class SimpleJdbc {
public static void main(String[] args)
throws SQLException, ClassNotFoundException {
// Load the JDBC driver
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded");
// Establish a connection
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/test", "******", "******");//user跟password匿了
System.out.println("Database connected");
// Create a statement
Statement statement = connection.createStatement();
// Execute a statement
ResultSet resultSet = statement.executeQuery
("select firstName, mi, lastName from Student where lastName = 'Smith' ");
// Iterate through the result and print the student names
while (resultSet.next())
System.out.println(resultSet.getString(1) + "\t" +resultSet.getString(2) + "\t" + resultSet.getString(3));
// Close the connection
connection.close();
}
}
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/test", "******", "******");
问题就是我安装的MySQL没有提示我输入user跟password,只输入password,现在我使用上面这条语句都出问题了,
我只知道自己MySQL数据库的密码,而不知道用户名,那该怎么办啊?
public static void main(String[] args)
throws SQLException, ClassNotFoundException {
// Load the JDBC driver
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded");
// Establish a connection
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/test", "******", "******");//user跟password匿了
System.out.println("Database connected");
// Create a statement
Statement statement = connection.createStatement();
// Execute a statement
ResultSet resultSet = statement.executeQuery
("select firstName, mi, lastName from Student where lastName = 'Smith' ");
// Iterate through the result and print the student names
while (resultSet.next())
System.out.println(resultSet.getString(1) + "\t" +resultSet.getString(2) + "\t" + resultSet.getString(3));
// Close the connection
connection.close();
}
}
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/test", "******", "******");
问题就是我安装的MySQL没有提示我输入user跟password,只输入password,现在我使用上面这条语句都出问题了,
我只知道自己MySQL数据库的密码,而不知道用户名,那该怎么办啊?
解决方案 »
- jar文件执行出错问题
- Java中总是出现ClassDefineFoundError。
- 怎么用 JAVA 编成实现 获得本机的 内存信息 和 操作系统 信息 以及硬盘信息呢 ?
- javascript的onclick动作传一个<%=ss%>变量,为什么不能解释该变量,郁闷
- 请问一个奇怪的问题:在Frame里,在panel上画一个圆,为什么运行后不显示,只有缩放运行窗口才能显示。谢谢
- 有一道JAVA题,请教各位论坛上高手~~
- 布局管理器到底起什么作用呀?谢啦~~~~~~~~~~~~~~
- Eclipse如何生成javadoc?
- 100分求解!!!
- WEB服务器怎样处理error?
- 再问CSV问题
- 请教一个文件内容替换的问题
SET password = PASSWORD('new_password')
WHERE user = 'root' AND host = 'localhost';这是系统级操作,请谨慎操作,操作前请先 SELECT 相同条件的数据做好备份。
Username:root(超级用户)
Password:(自己设置的)
UPDATE user
SET password = PASSWORD('new_password')
WHERE user = 'root' AND host = 'localhost';