JDBC দিয়ে টেবিল ড্রপ করা
Java-তে PreparedStatement ব্যবহার করে MySQL টেবিল ড্রপ করা যায়। নিচে ধাপে ধাপে প্রক্রিয়া দেখানো হলো।
টেবিল তৈরি এবং যাচাই
mysql> CREATE TABLE customerDetails (
-> CustomerId INT,
-> CustomerName VARCHAR(30)
-> );
mysql> SHOW TABLES;
Java কোড: DROP TABLE IF EXISTS
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class DropTableDemo {
public static void main(String[] args) {
Connection con = null;
PreparedStatement ps = null;
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test3?useSSL=false", "root", "123456");
ps = con.prepareStatement(
String.format("DROP TABLE IF EXISTS %s", "customerdetails"));
boolean result = ps.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
টেবিল ড্রপ হয়েছে কিনা যাচাই
mysql> SHOW TABLES;
আউটপুটে customerdetails টেবিলটি আর থাকবে না, যা প্রমাণ করে টেবিল সফলভাবে ড্রপ হয়েছে।