package testjdbc;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */public class test {
   private static Context getInitialContext() throws Exception {
    String url = "t3://theone:7001";
    String user = "system";
    String password = "systemboot";
    Properties properties = null;
    try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,
                     "weblogic.jndi.WLInitialContextFactory");
      properties.put(Context.PROVIDER_URL, url);
      if (user != null) {
        properties.put(Context.SECURITY_PRINCIPAL, user);
        properties.put(Context.SECURITY_CREDENTIALS,
                       password == null ? "" : password);
      }      return new InitialContext(properties);
    }
    catch (Exception e) {
      throw e;
    }
  }
  public static void main(String[] args) {
   
    DataSource ds=null;
    Context ctx=null;
    Connection myConn = null;    try{
      ctx = getInitialContext();
      ds = (DataSource)ctx.lookup("myJDataSource");
    }
    catch(Exception E){
      System.out.println("Init Error:"+E);
    }    Statement myStatement = null;
    ResultSet myResultSet = null;    try{      myConn = ds.getConnection();
      myStatement = myConn.createStatement();
      myResultSet = myStatement.executeQuery("SELECT full_name FROM employee");      while(myResultSet.next())
      {
        System.out.println("the empolyee full name is"+myResultSet.getString("full_name"));
      }
      myResultSet.close();
    }
    catch(SQLException e){
      System.out.println("Error code ="+ e.getErrorCode());
      System.out.println("Error Messgege =" + e.getMessage());
    }
    finally{
      try {
        if (myStatement != null) {
          myStatement.close();
        }
        if (myConn != null) {
          myConn.close();
        }
      }
        catch (SQLException e) {
          System.out.println("Error code =" + e.getErrorCode());
          System.out.println("Error Messgege =" + e.getMessage());
        }      }
    }}