Manash Kumar
inputDialogBox
1 Answer(s)      4 years and 3 months ago
Posted in : Framework

how to pass sql query from inputDialogbox and find the data from database plz help me

Advertisement
View Answers

March 25, 2011 at 3:01 PM


import java.sql.*;
import javax.swing.*;
class  Retrieve{
public static void main(String[] args){
    try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           String query=JOptionPane.showInputDialog(null,"Enter query");
           ResultSet rs=st.executeQuery(query);
           String name="",address="";
           if(rs.next()){
              System.out.println("Name: "+rs.getString("name"));
               System.out.println("Address: "+rs.getString("address"));
           }
    }
    catch(Exception e){}

    }
}









Related Tutorials/Questions & Answers:
inputDialogBox
inputDialogBox  how to pass sql query from inputDialogbox and find the data from database plz help me