You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cenk <ce...@yahoo.com> on 2007/08/28 10:30:36 UTC

getConnection?

Hello,

I have a problem to get connection.It keeps catching exception? Any ideas?

....
 String driverClass = ResourceManager.getString("database.driver");
 String dbUrl = ResourceManager.getString("database.url");
 String dbUser = ResourceManager.getString("database.user");
 String dbPassword = ResourceManager.getString("database.password");
 try{
     Class.forName(driverClass);
     con = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
 }catch(Exception exp){
     System.err.println("Could not connect to database.\n" +exp.getMessage());
 }
....

Here is the application resources.properties
#database connection properties
database.driver = COM.ibm.db2.jdbc.app.DB2Driver
database.url = jdbc:db2:YES
database.user = db2admin
database.password = db2admin


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: getConnection?

Posted by Simone Piva <js...@gmail.com>.
Sorry for the driver I used copy&paste from an old class I developed,
obviously use your driver class COM.ibm.db2.jdbc.app.DB2Driver for
registration...

On 8/28/07, Simone Piva <js...@gmail.com> wrote:
> Why are you using direct JDBC accesss instead of ConnectionPool
> offered by Application Server?
>
> However, rewrite your try block like this:
> try {
>       DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
>       con = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
>   }
>
> and it should work.
>
> On 8/28/07, Cenk <ce...@yahoo.com> wrote:
> > Hello,
> >
> > I have a problem to get connection.It keeps catching exception? Any ideas?
> >
> > ....
> >  String driverClass = ResourceManager.getString("database.driver");
> >  String dbUrl = ResourceManager.getString("database.url");
> >  String dbUser = ResourceManager.getString("database.user");
> >  String dbPassword = ResourceManager.getString("database.password");
> >  try{
> >      Class.forName(driverClass);
> >      con = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
> >  }catch(Exception exp){
> >      System.err.println("Could not connect to database.\n" +exp.getMessage());
> >  }
> > ....
> >
> > Here is the application resources.properties
> > #database connection properties
> > database.driver = COM.ibm.db2.jdbc.app.DB2Driver
> > database.url = jdbc:db2:YES
> > database.user = db2admin
> > database.password = db2admin
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: getConnection?

Posted by Simone Piva <js...@gmail.com>.
Why are you using direct JDBC accesss instead of ConnectionPool
offered by Application Server?

However, rewrite your try block like this:
try {
      DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
      con = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
  }

and it should work.

On 8/28/07, Cenk <ce...@yahoo.com> wrote:
> Hello,
>
> I have a problem to get connection.It keeps catching exception? Any ideas?
>
> ....
>  String driverClass = ResourceManager.getString("database.driver");
>  String dbUrl = ResourceManager.getString("database.url");
>  String dbUser = ResourceManager.getString("database.user");
>  String dbPassword = ResourceManager.getString("database.password");
>  try{
>      Class.forName(driverClass);
>      con = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
>  }catch(Exception exp){
>      System.err.println("Could not connect to database.\n" +exp.getMessage());
>  }
> ....
>
> Here is the application resources.properties
> #database connection properties
> database.driver = COM.ibm.db2.jdbc.app.DB2Driver
> database.url = jdbc:db2:YES
> database.user = db2admin
> database.password = db2admin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org