您好,欢迎访问一九零五行业门户网

java判断数据库是否存在

java判断数据库是否存在的代码:
public static boolean isexistdatabase(string database) { connection conn = null; statement stmt = null; resultset rs = null;// 数据库结果集 try { conn = getconnection(); stmt = conn.createstatement(); string sql = "select count(*) from information_schema.schemata where schema_name=\"" + database + "\""; system.out.println(sql); rs = stmt.executequery(sql); if (rs.next()) { if (rs.getint(1) == 0) { return false; } else { return true; } } return false; } catch (exception e) { throw new tenantexception(e.getmessage(), status.internal_server_error); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (sqlexception e) { throw new tenantexception("mysql关闭连接失败:" + e.getmessage(), status.internal_server_error); } } }
关键sql语法:
string sql = "select count(*) from information_schema.schemata where schema_name=\"" + database + "\"";
更多java知识请关注java基础教程栏目。
以上就是java判断数据库是否存在的详细内容。
其它类似信息

推荐信息