jdbc hello world

I am in a java mood today, let’s check how to print hello world with jdbc :)

import java.sql.*;
public class HelloWorld {
  public  static void main(String[] args) throws SQLException {
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    ResultSet res = DriverManager.
      getConnection("jdbc:oracle:thin:@srv1:1521:DB01", "scott", "tiger").
      prepareCall("select 'Hello World' txt from dual").
      executeQuery();
    res.next();
    System.out.println(res.getString("TXT"));
  }
}

let’s compile
javac -classpath $ORACLE_HOME/jdbc/lib/classes12.jar HelloWorld.java

and run

$ java -classpath $ORACLE_HOME/jdbc/lib/classes12.jar:. HelloWorld
Hello World

that’s all folks!

8 thoughts on “jdbc hello world”

  1. Just one problem: find the correct version of classes12.jar

    Performance team is fond of this solution :)

  2. A java is a good program, and a nice way to develop with oracle database.
    JDBC Thin doesn’t need tnsnames… that’s nice. But if need to use RAC(TAF) JDBC OCI may a better way …

    By the way, Connection Pooling + Caching are good thing to learn and …

    Enjoy!

  3. Pingback: jdbc hello world | Oracle

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>