WHY WHEN I EXECUTE THE BELOW CODE I GETS AN EXCEPTION java.sql.SQLException: No ResultSet was produced.........BUT EVEN THOUGH INSERTION OPERATION WORKS FINE........CAN ANYONE TELL ME WHY THIS EXCEPTION COMES

Connection co;
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        co = DriverManager.getConnection("jdbc:odbc:hh");
        Statement st1; 
        ResultSet result;
        st1 = co.createStatement();
        result=st1.executeQuery("select count(*) from rooms");
        result.next();
        int cn = result.getInt(1);
        System.out.println("count"+cn);
        String depart = (String) dept1.getSelectedItem();
        if("Others".equals(depart))
        {
        cn++; 
        st1.executeQuery("insert into rooms (room_number, serial, depart) values('"+room_no1.getText()+"','"+cn+"','"+others1.getText()+"')");
        }
        st1.close();
        } catch (Exception ex) {System.out.print(ex);}

Edited 5 Years Ago by Jessurider: n/a

Hi nidhish

According to 9th line you have used result.next() without any if
statement.
If your table is empty while executing first time result.next() will throw
an error.

Got it?

Another problem is for ddl statements you should use executeUpdate.
for dml you shoul use executeQuery.
According to 16th line you should use executeUpdate..

This question has already been answered. Start a new discussion instead.