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

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.