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
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