Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC SELECT query using executeUpdate() instread of executeQuery()
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Kiran Kumar Reddy
SELECT query using executeUpdate() instread of executeQuery()
1 Answer(s)      3 years and 11 months ago
Posted in : JDBC


for Ex:  class sample{
   public static void main(String a[]){
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:orcl", "", "");
        String str="Slect * from EMP";
        Statement st=con.createStatement();
        try{
            st.executeUpdate("select * from EMP"); //gives us Exception
                }
        catch(SQLException ex)
        {
                    // I want actuval code here.
                   //CODE here

 }
 //catch
 }
 //try
 }
 //main
 }
 //class

Advertisement
View Answers

January 21, 2011 at 11:14 AM


Hi Friend,

No, it is not possible.If you use executeUpdate() method with select quesry then you can't be able to retrieve data from the database.

Try this:

import java.sql.*;
class sample{
    public static void main(String[] args){
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data");
           while(rs.next()){
               System.out.println(rs.getString("name")+" "+rs.getString("address"));
           }
        }
        catch(Exception e){
        }
    }
}

Thanks



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com