> creating jdbc statements ~ Online tutorial

creating jdbc statements

Creating JDBC Statements

  • A Statement object is what sends your SQLstatement to the DBMS.
  • You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send.
  • For a SELECT statement, the method to use is
    executeQuery .
  • For statements that create or modify tables, the method to use is executeUpdate .

It takes an instance of an active connection to create a Statement object. In the following
example, we use our Connection object con to create the Statement object stmt :

Statement stmt = con.createStatement();


At this point stmt exists, but it does not have an SQL statement to pass on to the DBMS.
We need to supply that to the method we use to execute stmt . For example, in the
following code fragment, we supply executeUpdate with the SQL statement from the
example above:

stmt.executeUpdate("CREATE TABLE COFFEES " +
"(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
"SALES INTEGER, TOTAL INTEGER)");

Since we made a string out of the SQL statement and assigned it to the variable
createTableCoffees , we could have written the code in this alternate form:
stmt.executeUpdate(createTableCoffees);

Buy It Now








Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: