
I wanted to know if it is possible to create a database in mysql by letting the user enter the name of the database in swing gui..im doing my project in netbeans...Thank You

Java Create database using Swing
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
class CreateDatabase
{
public static void main(String[] args)
{
JFrame f=new JFrame();
JLabel lab=new JLabel("Enter Database name: ");
final JTextField text=new JTextField(20);
JButton b=new JButton("Create");
f.setLayout(null);
lab.setBounds(10,10,150,20);
text.setBounds(180,10,150,20);
b.setBounds(180,40,100,20);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=text.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement stmt=con.createStatement();
String sql = "CREATE DATABASE "+st;
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Database is created successfully");
}
catch(Exception ex){}
}
});
f.add(lab);
f.add(text);
f.add(b);
f.setVisible(true);
f.setSize(350,100);
}
}
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.