simpleTest - rs.close INSERT ret =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.sql.*; i public class simpleTest { p public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) {System.out.println("No driver");} try { Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/books", "rlent", "abc123"); // Do something with the Connection Statement stmt = null; ResultSet rs = null; int ret; stmt = conn.createStatement(); // SELECT / rs = stmt.executeQuery("SELECT firstName,lastName FROM authors"); ResultSetMetaData metaData = rs.getMetaData(); System.out.println("- Results of SELECT"); rs.next(); System.out.println(rs.getObject(1) + " " + rs.getObject(2) ); while ( rs.next() ) { System.out.println(rs.getObject(1) + " " + rs.getObject(2) );
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } rs.close(); // INSERT / ret = stmt.executeUpdate("INSERT INTO authors (firstName, lastName) VALUES ('Fred', 'Flinstone')" ); System.out.println("- Rows affected by insert: " + ret ); // UPDATE / ret = stmt.executeUpdate("UPDATE authors SET firstName='Barnie' WHERE firstName='Fred'"); System.out.println("- Rows affected by update: " + ret ); // DELETE / ret = stmt.executeUpdate("DELETE FROM authors WHERE firstName='Barnie'"); System.out.println("- Rows affected by delete: " + ret ); conn.close(); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } // main }...
View Full Document

This note was uploaded on 07/14/2011 for the course COP 4610L taught by Professor Staff during the Spring '09 term at University of Central Florida.

Page1 / 2

simpleTest - rs.close INSERT ret =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online