查询mysql库中所有表名的问题。。。
sql="show tables";
rs=statement.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString(2));
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TestMySql {
public static void main(String[] args) {
Connection con = null;
java.sql.PreparedStatement statment = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager
.getConnection("jdbc:mysql://localhost/mysql?user=root&password=");
con.setAutoCommit(false);
String sql = "show tables;";
statment = con.prepareStatement(sql);
rs = statment.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
statment.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
columns_priv
db
func
help_category
help_keyword
help_relation
help_topic
host
proc
procs_priv
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user