
i wanted to create a gui desktop application .that can take the database name and mysql password from text box, and after the click of a button it should show connection status,and go for next from there on button click we can execute my query,on any other operation

Here is your required code.
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.sql.*;
class CheckConnection{
public static void main(String arg[]){
JFrame frame=new JFrame();
JLabel label1 = new JLabel();
label1.setText("Enter Database Name:");
final JTextField text1 = new JTextField(20);
JLabel label2 = new JLabel();
label2.setText("Enter Mysql Password:");
final JPasswordField text2 = new JPasswordField(20);
JButton button=new JButton("submit");
JPanel panel=new JPanel(new GridLayout(3,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String database=text1.getText();
String pass=text2.getText();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+database, "root", pass);
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from data");
while(rs.next()){
System.out.println(rs.getString("name")+" "+rs.getString("address"));
}
}
catch(Exception e){
}
}
});
frame.add(panel,BorderLayout.CENTER);
frame.setTitle("Check Connection");
frame.setSize(300,100);
frame.setVisible(true);
}
}
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.