
i want to let the user select the name of database and then delete that database.......im doing project in swings netbeans

Java JDBC delete database
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class DeleteDatabase{
public static void main(String[] args){
JFrame f=new JFrame();
f.setLayout(null);
JLabel lab=new JLabel("Select");
final JComboBox combo=new JComboBox();
JButton b=new JButton("Delete");
combo.addItem("<-Select->");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "root");
final Statement st = con.createStatement();
ResultSet rs = st.executeQuery("show databases");
while (rs.next()) {
combo.addItem(rs.getString("Database"));
}
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String str= combo.getSelectedItem().toString();
try{
String sql = "DROP DATABASE "+str+"";
st.executeUpdate(sql);
}
catch(Exception ex){}
JOptionPane.showMessageDialog(null,"Database deleted successfully");
}
});
}
catch(Exception e){}
lab.setBounds(10,10,100,20);
combo.setBounds(120,10,150,20);
b.setBounds(120,40,100,20);
f.add(lab);
f.add(combo);
f.add(b);
f.setVisible(true);
f.setSize(350,150);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.