Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: Persistence with JDBC ???

sandeepK

2005-11-28

Replies:

Hi Carlos,

Since you are migrating the application from pl/sql to J2EE
I guess JDBC is a good solution until unless the number of concurrent users
are more than 1000
we are also in the prcoess of migrating an application from Ingress
platform to Java Struts.
well The connection manager is able to handle the request efficiently.
package mpr;



import java.io.*;
import java.sql.*;
import javax.sql.*;


public class MyConnection
{
private static MyConnection self = new MyConnection();
public Connection myConnection;


private MyConnection()
{
myConnection = null;
}

public MyConnection(Connection conn)
{
myConnection = conn;
}


public static MyConnection getInstance()
{
    return self;
  }



  public Connection receiveConnection()
    {
      return myConnection;
    }
  public void closeConnection(Connection c)
  {
  try
  {
     c.close();
  }catch(SQLException e)
  {
  System.out.println("Inside My Connection SQLException
"+e.getMessage());
  }catch(NullPointerException npe)
  {
   System.out.println("Inside NPE "+ npe.getMessage());
  }
  }

}

package mpr;

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

public class ConnectionManager
{
private static String dbName = null;
private static String url = null;
private static String driver = null;
private static String userName = null;
private static String passwd = null;

public int i = 0;


public ConnectionManager()
{

}
public static MyConnection createConnection(String type)
{
Connection conn = null;
int dbType=0;
if(type.equals("Oracle")) dbType = 1;
else if(type.equals("Ingres")) dbType = 2;
else if(type.equals("Ingrescom")) dbType = 4;
else dbType = 3;
switch (dbType)
{
       case 1: dbName= "Oracle";
        driver= "oracle.jdbc.OracleDriver";
        url="jdbc:oracle:thin:@(protected)";
        userName="smldev";
        passwd="god";

       break;

      case 2:
   dbName = "Ingres";
        driver= "com.cariboulake.jsql.JSQLDriver";
        url="jdbc:caribou:jsqlingres://hwr08:6024/hwr04::mmdb";
        userName="webdev";
        passwd="netmat2";
       break;

       case 3:
       dbName = "Oracle";
       driver= "oracle.jdbc.OracleDriver";
       url="jdbc:oracle:thin:@(protected)";
       userName="inddev";
       passwd="inddev";
       break;

      case 4:
   dbName = "Ingrescom";
        driver= "com.cariboulake.jsql.JSQLDriver";
        url="jdbc:caribou:jsqlingres://hwr08:6024/hwr09::comfax";
        userName="inddev";
        passwd="";
       break;
     default:
       break;

    }
System.out.println(conType());
try
 {
    Class.forName(driver);
    conn = DriverManager.getConnection(url,userName,passwd);
  }catch(ClassNotFoundException c)
  {
  System.out.println("Class Not Found!!"+c.getMessage());
  }
  catch(SQLException s)
{
 System.out.println("inside SQLException"+s.getMessage());
}
catch(NullPointerException sd)
{
 System.out.println("Inside NPE"+sd.getMessage());
}
return new MyConnection(conn);

}

public static void closeConnection(Connection c)
  {
  new MyConnection(c).closeConnection(c);
  }

 public static String conType()
 {
  return "\n DataBase : "+dbName+"\n URL: "+url+"\n Driver:
"+driver+"\n"+"User: "+userName;
 }



}

----- Original Message -----
From: "Juan Carlos" <jandriver1.0@(protected)>
To: <J2EEPATTERNS-INTEREST@(protected)>
Sent: Monday, October 10, 2005 10:20 PM
Subject: Persistence with JDBC ???


> Hi everybody, I'm migrating a legacy system from pl/sql to J2EE.
> Initially i had to use an implementation of JDO, but after trying to
> translate lots of query without getting a good performance and, in many
> cases, being almost impossible to translate them, we are planning to use
> other persistence system. Some people suggested me to use JDBC and call
> directly stored functions or execute statements.
> I've tried it and it performs much faster than with JDO. I think it's
> normal, since now we are avoiding to create the objects and simplifying
> considerably the number of queries (JDO generates lots).
>
> Although JDBC is faster, I know that there are some issues I should
> consider before adopting it. The one that more worries me is the cache
> management. The system manages lots of data and users, and same queries
> are invoked once and other.
>
> Do you think that JDBC is a good solution? Is that enough for a big
> web-based system?
>
> I know that I could use Hibernate but initially the chiefs didn't want
> to use free software for persistence, since is a very critical system
> and they always want to have some comercial ''support''..
> Another thing is that the system is based only in servlets (with Struts)
> and doesn't use any kind of EJB.
>
> Thanks in advance!!
>
> ====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
> http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to
> listserv@(protected)
>

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.