What does this mean ? Statement st=con.CreateStatement(); how method of Statement interface is accessed by Connection interface reference con ? please help me to understand the concept...

Recommended Answers

All 6 Replies

are you talking about createStatement ?
this is a method from the Connection interface, returning a Statement.
just check here .

EDIT: the Statement interface doesn't have a createStatement method, by the way. if you check the api, you'll see this:

See Also:
Connection.createStatement(), ResultSet

which is basicly telling: the createStatement method of the Connection interface is related to the Statement interface. it's not part of it, though.

try {
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
        String coffeeName = rs.getString("COF_NAME");
        int supplierID = rs.getInt("SUP_ID");
        float price = rs.getFloat("PRICE");
        int sales = rs.getInt("SALES");
        int total = rs.getInt("TOTAL");
        System.out.println(coffeeName + "\t" + supplierID +
                           "\t" + price + "\t" + sales +
                           "\t" + total);
    }
}

Thank you for clarifing my doubt....

con.setAutoCommit(true); the parameter to this method is true by default...why is it so ?? please help me know the reason for the default value true..

Read the API doc for The Connection class, setAutoCommit method.

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.