我想在java程序中列出某个MySQL实例下的数据库和表,比如像MySQL的ODBC配置程序那样的.
解决方案 »
- 为什么Mysql的Qcache_free_memory还很大,但是Qcache_lowmem_prunes却不为0且一直在增加?
- 约束条件 为纯中文字符串
- 执行 mysql_real_query, 如果服务器忙,会不会抛出超时的异常。
- mysql 中DISTINCT 和limit哪一个先执行呢?
- 求一SQL语句。正确马上给分。谢谢!
- 请教mysqldump的远程数据备份问题
- between and 这个命令能否表示2004-04-03<a<204-05-06
- DELPHI+ADO+MYSQL的中文问题!
- delete from
- 求:mysql字母大写自动转换成小写
- 触发器中可以创建表吗?
- mysql 查询优化的怪事,跟大家分享一下
执行一条SQL语句,将记录集读到一个数组里就可以了嘛~
import java.sql.*;public class GetMysqlDatabaseName {
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/zhxsqlstudy", "user", "username"
);
// 执行show databases,返回结果保存在res中
stmt = conn.createStatement();
res = stmt.executeQuery("show databases");
// 将数据库名称打印出来。至于怎么处理随你高兴。
while (res.next()){
String databaseName = res.getString("Database");
System.out.println("Database " + databaseName);
}
res.close();
} catch(Exception e){
System.out.println("Error " + e.toString());
}
}
}