TestThinDSApp.java Source code

Java tutorial

Introduction

Here is the source code for TestThinDSApp.java

Source

import java.sql.*;
import oracle.jdbc.pool.*;

public class TestThinDSApp {

    public static void main(String args[]) throws ClassNotFoundException, SQLException {

        // These settings are typically configured in JNDI
        // so they a implementation specific
        OracleDataSource ds = new OracleDataSource();
        ds.setDriverType("thin");
        ds.setServerName("dssw2k01");
        ds.setPortNumber(1521);
        ds.setDatabaseName("orcl"); // sid
        ds.setUser("scott");
        ds.setPassword("tiger");

        Connection conn = ds.getConnection();

        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery(
                "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
        if (rset.next())
            System.out.println(rset.getString(1));
        rset.close();
        stmt.close();
        conn.close();
    }
}