O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending a Query via JDBC

Statement stmt = conn.createStatement( );
											ResultSet rs =
											stmt.executeQuery(
											"SELECT * from users where name='tim'");

In this phrase, we create a JDBC statement using the Connection object’s createStatement() method and use it to execute a query that returns a Java ResultSet. To create a connection, see the previous phrase, “Connecting to a Database via JDBC.” When performing a SELECT query, we use the executeQuery() method of the Statement object.

If we wanted to perform an UPDATE operation rather than a SELECT query, we would use the executeUpdate() method of the Statement object, instead of the executeQuery() method. The executeUpdate() method is used with SQL INSERT, UPDATE, and DELETE statements. The executeUpdate() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required