Describe with an example how to send SQL statements to databases for execution.
The following illustrates with examples, to send SQL statements to databases for execution:
- The SQL statements are to be created as objects. These objects are to be assigned to Statement reference.
Example:
Statement stmts = con.createStatement();//creates a statement object
- The specific SQL statements are to be executed and the result should be captured
Example:
ResultSet rsltSet = stmts.executeQuery(“select * from emp”);
- To make a row inserted into the database and committed:
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from emp");
rs.moveToInsertRow();
rs.updateInt(1,15); // first attribute with value 15
rs.updateString(2,"Vismay”); // second value with Vismay
rs.updateFloat(3,4500); // third attribute with 4500
rs.insertRow();
con.commit();