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);}

Because you used executeQuery instead of executeUpdate

PS: Writing with Caps Lock is like shouting, that is considere rude.

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

thanks................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.