JDBC 删除表
2018-03-21 14:11 更新
JDBC教程 - JDBC删除表
以下代码显示如何从MySQL数据库删除表。
它发出drop table命令如下。
DROP TABLE Person
例子
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class Main { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/STUDENTS"; static final String USER = "username"; static final String PASS = "password"; public static void main(String[] args) throws Exception { Connection conn = null; Statement stmt = null; Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); System.out.println("Deleting database..."); stmt = conn.createStatement(); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(); String sql = "DROP TABLE Person "; stmt.executeUpdate(sql); System.out.println("Created table in given database..."); stmt.close(); conn.close(); } }
以上内容是否对您有帮助:
← JDBC 创建表
更多建议: