Drop Table in Java


Leave a reply                     

Drop MySql Table

How to Drop MySql Table Using executeUpdate

Java Drop MySql Table

Java Delete MySql Table

Following Query executed through Statement to Drop table tablename from database databasename.
DROP TABLE tablename

package raghuwansh.java.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DropTable {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection connection = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/databasename", "root", "");
			Statement statement = connection.createStatement();
			statement
					.executeUpdate("DROP TABLE tablename");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *


9 + = fifteen