package ce.core;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
select column_name from information_schema.columns where table_schema='csdb' and table_name='users'
*
*
* @author ZengWenfeng
*
*/
public class MySQL_DB_Util
{
public static Connection con;
public Connection getConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
con = DriverManager.getConnection("jdbc:mysql://192.168.10.136:3306/mysql?characterEncoding=UTF-8", "root", "root");
}
catch (SQLException e)
{
e.printStackTrace();
}
return con;
}
public static void main(String[] args)
{
MySQL_DB_Util c = new MySQL_DB_Util();
c.getConnection();
String db = "rpaweb1";
// select table_name from information_schema.tables where table_schema='rpa1'
String sql = "select table_name from information_schema.tables where table_schema='" + db + "'";
PreparedStatement ps = null;
ResultSet rs = null;
try
{
ps = con.prepareStatement(sql);// 第二步:预编译
// 第四步执行sql
rs = ps.executeQuery();
while (rs.next())
{
String table_name = rs.getString("table_name");
String str = "GRANT SELECT ON " + db + "." + table_name + " TO 'rpaquery'@'%';";
System.out.println(str);
}
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
MySQL_DB_Util
最新推荐文章于 2022-07-25 18:17:08 发布