JDBC 删除数据库
2018-03-21 14:10 更新
JDBC教程 - JDBC删除数据库
以下代码显示如何删除数据库。
它发出以下SQL命令来执行放置操作。
DROP DATABASE STUDENTS
例子
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/"; 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(); String sql = "DROP DATABASE STUDENTS"; stmt.executeUpdate(sql); stmt.close(); conn.close(); } }
以上内容是否对您有帮助:
更多建议: