import java.sql.*; /** * HelloWorldJDBC Popcorn sample. This sample is based on the JDBC Tutorial found * at http://www.raima.com/jdbc-tutorial/. Please find expanded explanations * there. * * This sample creates a database with a single table containing a single * character string column. One row is created, and the column value is * set to "Hello World". Then the database is queried so that the column * value can be read from the database and printed out. That's it! Repeated * executions of this program will result in multiple lines. **/ public class HelloWorldJDBC { public static void main (String[] args) throws SQLException { Connection Conn = DriverManager.getConnection ("jdbc:raima:rdm://local"); try { Statement Stmt = Conn.createStatement (); try { try { Stmt.execute ("CREATE DATABASE hello_db"); Stmt.execute ("CREATE TABLE hello_table (f00 char(31))"); Conn.commit (); } catch (SQLException exception) { // Okay if database exists Stmt.execute("OPEN DATABASE hello_db"); } // Insert one row, column value = "Hello World" Stmt.executeUpdate ("INSERT INTO hello_table VALUES (\"Hello World\")"); Conn.commit (); ResultSet RS = Stmt.executeQuery ("SELECT * FROM hello_table"); try { while (RS.next() != false) { System.out.println (RS.getString (1)); } } finally { RS.close (); } } finally { Stmt.close (); } } catch (SQLException exception) { System.err.println ("SQLException : " + exception.toString ()); } finally { Conn.close (); } } }