The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

jdbc

Posted by uday on October 20, 2001 at 1:25 AM

> > > IN EJB Bean Managed Persistence, I want to use MS-ACCESS database( not Cloudscape) using sun.jdbc.odbc.JdbcOdbcDriver driver.How can I go ahead with this,Please give all steps.

> > > DO REPLY

> > > Thankx
> > > Harendra

> >
> > HI Harendra

> > I am attaching this code for the getConnection Method for the BMP Bean

> > private Connection getConnection() throws SQLException
> > {
> > InitialContext initCtx = null;
> > try
> > {
> > initCtx = new InitialContext();
> > DataSource ds = (javax.sql.DataSource)
> > initCtx.lookup("weblogic.jdbc.jts.oraclePool");
> > System.out.println("Pool found");
> > return ds.getConnection();
> > }
> > catch(NamingException ne)
> > {
> > log("UNABLE to get a connection from oraclePool!");
> > throw new EJBException(ne);
> > }
> > finally
> > {
> > try
> > {
> > if(initCtx != null) initCtx.close();
> > }
> > catch(NamingException ne)
> > {
> > log("Error closing context: " + ne);
> > throw new EJBException(ne);
> > }
> > }
> > }

> >
> > In the above code
> > "initCtx.lookup("weblogic.jdbc.jts.accessPool");"

> > this line is actually doing the job getting the connection pool

> > You set this in the weblogic properties file search for

> > #weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.demoPool=demoPool

> > and replace it with

> > weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.accessPool=demoPool

> > demopool is the name of ur Access connection pool name.which u can write by changing the demo pool in th properties file.

> > weblogic.jdbc.connectionPool.demoPool=\
> > url=jdbc:odbc:demo,\
> > driver=COM.cloudscape.core.JDBCDriver,\
> > initialCapacity=1,\
> > maxCapacity=2,\
> > capacityIncrement=1,\
> > props=user=none;password=none;server=none

> > where in the url demo is the odbc driver name set for MS Access BD.

> > i hope this would be sufficient and would solve ur doubt


> >>

> Hi Harendra,

> Try this one out:

> import java.sql.*;
> import javax.sql.*;
> import java.util.*;

> public class MsConnection
> {

> public static void sqlSelect(String sqltext)
> {
> boolean more = false;
> int colCount = -1;
> try
> {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

> Connection c = DriverManager.getConnection("jdbc:odbc:DACCU", "daccu1", "05041963");
> if(c == null)
> System.out.println("Connection failed");
> else
> {
> System.out.println("Connection succeded");
> }

> Statement stm = c.createStatement();
> ResultSet rs = stm.executeQuery(sqltext);
> ResultSetMetaData rsdt = rs.getMetaData();
> colCount = rsdt.getColumnCount();
> System.out.println("colums: " + rsdt.getColumnCount());
> System.out.println("rows: " + rs.getRow() );
> more = rs.next();
> while(more)
> {
> for(int col=1; col<= colCount; col++)
> {
> System.out.print( rs.getString(col) + "***");
> }
> System.out.println("\n");

> more = rs.next();

> }

> }
> catch(Exception sql)
> {
> sql.printStackTrace();
> }
> }
> public static void main(String args[])
> {
> MsConnection msConnection = new MsConnection();
> msConnection.sqlSelect("Select * from employee");

>
> }

> }
> Hope it help. If you are still having problem, please let me know






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us