the below code exlpains that the execute update statement gives exception in the case of
JdbcOdbcDriver but not in case of OracleDriver
so it is not always necesarry that select statement will give exception in executeUpdate("Select * ...");
but it depends on the Drive we register in DriverManager.registerDriver(Driver ob);
some Driver May give Exception while some will not
but the answer to your question is you should not use executeUpdate("Sel..")
for select Statement even if doesn't give Exception read the below code and and comment you will understand better
import java.sql.*;
import sun.jdbc.odbc.*;
import oracle.jdbc.driver.*;
public class MyDb {
public static void main(String args[]) throws Exception {
//drive is oracle.jdbc.driver.OracleDriver;
OracleDriver od = new OracleDriver();
DriverManager.registerDriver(od);
Connection conn;
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "system");
Statement stm = conn.createStatement();
int val = stm.executeUpdate("select * from mylog");
System.out.println(val);
//output for above code is 10 actually the table had 15 rows
//but when table had 7 rows output was 7 ,when number of rows where 9 output was 9
//but when the number of row in table were more than or equal to 10 the out put was 10
//so actually it is no meaning to use select statement within executeQuery
//even if it doesn't give exception
//driver is sun.jdbc.odbc.JdbcOdbcDriver;
JdbcOdbcDriver od2 = new JdbcOdbcDriver();
DriverManager.registerDriver(od2);
Connection conn2 = DriverManager.getConnection("jdbc:odbc:swap", "system", "system");
Statement stm2 = conn2.createStatement();
int val2 = stm2.executeUpdate("select * from mylog");
//while this code gives exception
//Exception in thread "main" java.sql.SQLException: No row count was produced
// at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
// at MyDb.main(MyDb.java:19)
System.out.println(val2);
}
}