检测数据库中是否存在某一张表
来源:互联网 发布:php错误日志 编辑:程序博客网 时间:2024/05/22 12:23
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class MysqlTest1 {public static void main(String[] args) throws Exception {testPrepareStatement("test");}public static void testPrepareStatement(String tableName) {Connection conn = getConnection();PreparedStatement ps = null;try {String sql = "show tables from test like '"+tableName+"'";ps = conn.prepareStatement(sql);ResultSet rs = ps.executeQuery();boolean isTableExist = rs.first();System.out.println(isTableExist);} catch (Exception e) {e.printStackTrace();} finally {close(conn);}}public static Connection getConnection() {Connection conn = null;try {Class.forName("com.mysql.jdbc.Driver");String url = "jdbc:mysql://localhost:3306/test?characterEncoding=utf-8";conn = DriverManager.getConnection(url, "root", "test");} catch (Exception e) {e.printStackTrace();}return conn;}public static void close(Connection conn,Statement st) {if(conn!=null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}if(st!=null) {try {st.close();} catch (SQLException e) {e.printStackTrace();}}}public static void close(Connection conn) {if(conn!=null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}public static void close(Statement st) {if(st!=null) {try {st.close();} catch (SQLException e) {e.printStackTrace();}}}}
0 0
- 检测数据库中是否存在某一张表
- mysql 查看是否存在某一张表
- mysql判断某一张表是否存在
- 用SQL查找Access数据库中某一表是否存在的一种方法
- 工具类:检查数据库表是否存在某一列
- 判断表中某一字段是否存在并删除
- MySQL判断表中是否存在某一字段
- 判断数组中是否存在某一元素
- Qt数据库操作,检测表中是否存在某条数据
- 判断数据库中是否存在某个表
- 判断数据库中是否存在表
- 判断数据库中是否存在表
- 判断表是否存在当前数据库中
- 检查数据库中一个表是否存在
- MySQL查找数据库中是否存在表
- Android检测表是否存在
- 表是否在数据库中,字段是否存在表中
- 数据库 表 是否存在
- javaScript中的假值
- 使用SwingWorker之二
- 手动9 - 安装vsftpd
- Linux SSh scp使用【远程传输】
- ZJU PAT 1018 锤子剪刀布
- 检测数据库中是否存在某一张表
- 第十一篇 ANDROID 系统网络连接和管理机制 .
- 使用SwingWorker之三
- CheckedListBox控件使用
- oracle闪回数据库详解
- 程序员新职位--全栈工程师
- ASP.NET的跨页面控件传值常用方法(续)
- 四翼——硬件定义
- 【加拿大印象】性感健康阳光的女人