This is how I always do....


import java.sql.*;

public class DB {
 private static javax.sql.DataSource ds = null;

 //Initieringsblock
 static {
  String dbsource = "jdbc/MyPooledDS";

  try
  {
   javax.naming.Context ctx = new javax.naming.InitialContext();
   if (ctx == null) {
    System.out.println("No context!");
   }
   ds = (javax.sql.DataSource)ctx.lookup(dbsource);
  }
  catch(javax.naming.NamingException namExc)
  {
   ds = null;
   namExc.printStackTrace();
   throw new java.lang.RuntimeException("Failed to get datasource!!");

  }
 }

 public DB()  {}

 public static java.sql.Connection getConnection() throws
java.sql.SQLException {
  return ds.getConnection();
 }


}


then I just call

Connection conn = DB.getConnection();

from my apps/beans/whatever


Johan
----- Original Message -----
From: "kevin1" <[EMAIL PROTECTED]>
To: "Orion-Interest" <[EMAIL PROTECTED]>
Sent: Wednesday, June 20, 2001 2:06 AM
Subject: Newbie - using EJB and databases


>
> Hello all,
> I am still new to the whole EJB thing, but I have a grasp on it.  However,
> the one thing I am foggy on is how to use a database.  I know that I set
up the
> db connection in the data-sources.xml file, but what is the syntax to use
that
> in an application?  Where could I find an example of that?


Reply via email to