TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
document.body.oncopy = function () {
if (window.clipboardData) {
setTimeout(function () {
var text = clipboardData.getData("text");
if (text && text.length > 300) {
text = text + "
本文来自CSDN博客,转载请标明出处:" + location.href;
clipboardData.setData("text", text);
}
}, 100);
}
}
function StorePage() { d = document; t = d.selection ? (d.selection.type != "None" ? d.selection.createRange().text : "") : (d.getSelection ? d.getSelection() : ""); void (keyit = window.open("http://www.365key.com/storeit.aspx?t=" + escape(d.title) + "&u=" + escape(d.location.href) + "&c=" + escape(t), "keyit", "scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes")); keyit.focus(); }
方法是通过查询数据库meta数据来获取数据表。
public static Boolean doesTableExist(String tablename) {
Connection con = null;
HashSet<String> set = new HashSet<String>();
try {
Class.forName(DatabaseConnection.getDatabaseConnection());
con = DriverManager.getConnection(DatabaseName.con);
DatabaseMetaData meta = con.getMetaData();
ResultSet res = meta.getTables(null, null, null,
new String[]{"TABLE"});
while (res.next()) {
set.add(res.getString("TABLE_NAME"));
}
res.close();
con.close();
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
}
//System.out.println(set);
return set.contains(tablename.toUpperCase());
}
其中只需要替换DatabaseConnection.getDatabaseConnection() 和DatabaseName.con 为你需要连接的数据库就好了。可以参考另一篇文章如何连接埠通的数据库:http://blog.csdn.net/autofei/arcHive/2010/05/24/5621274.aspx
另外一个方法就是尝试连接数据库,然后捕获异常。
//connection = new DatabaseConnection(DatabaseConnection.DERBY, "", "db", "uncc", "uncc");
connection = new DatabaseConnection(DatabaseConnection.POSTGRES, "localhost", "postgres",
"postgres", "postgres");
database = new Database(connection);
// Checks to see if database structure already exists
boolean exists = true;
Statement stmt = connection.getStatement();
try {
stmt.executeQuery("SELECT * FROM qgram");
} catch (Exception e) {
connection.rollback();
exists = false;
}
参考:http://www.herongyang.com/jdbc/JDBC-ODBC-Flat-File-List-Tables.HTML |
|