Test DataSource LookUp : Oracle JDBC : Database SQL JDBC : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Database SQL JDBC   » [  Oracle JDBC  ]  Screenshots 
 



Test DataSource LookUp

/*

Java Programming with Oracle JDBC
by Donald Bales 
ISBN: 059600088X
Publisher: O'Reilly

*/


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class TestDSLookUp {

  public static void main(String[] argsthrows SQLException, NamingException {

    Context ctx = null;
    try {
      Properties prop = new Properties();
      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
          "com.sun.jndi.fscontext.RefFSContextFactory");
      prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
      ctx = new InitialContext(prop);
    catch (NamingException ne) {
      System.err.println(ne.getMessage());
    }

    DataSource ds = (DataSourcectx.lookup("joe");
    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();
  }
}

           
       
Related examples in the same category
1.  Get Object From Oracle Database Using STRUCTHas Download File
2.  Inser BLOG(Picture or Photo) Data Type Into Oracle DatabaseHas Download File
3.  Serialized And Deserialize Object OracleHas Download File
4.  Get Oracle Table NamesHas Download File
5.  Get Parameter MetaData From Oracle JDBC DriverHas Download File
6.  Test Oracle JDBC Driver Installation
7.  Create Employee Table Oracle
8.  Count row in Oracle
9.  Get Column Names From ResultSet for Oracle
10.  Demo ResultSet Oracle
11.  All data types for Oracle
12.  Get Column Privileges Oracle
13.  Test OCINet 8 App
14.  Test SSL
15.  Test Data Encryption Integrity
16.  OracleDataSource Demo
17.  Register custome type to Oracle
18.  Insert custom type to Oracle
19.  Check JDBC Installation for Oracle
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.