Re: help creating datasource

From: David McDivitt (x12code-del_at_del-yahoo.com)
Date: 10/14/04

  • Next message: Lionel: "Hibernate and multiple datasources..."
    Date: Thu, 14 Oct 2004 14:02:54 -0500
    
    

    The following works for me. No response needed. Thanks

    import java.sql.Connection;
    import java.sql.Driver;
    import java.util.Properties;

    public class DB2TestC {
        private static final String dbName = "jdbc:db2:AID987C";
        private static final String dbUser = "AID987C";
        private static final String dbPassword = "none";
        
        public static void main(String[] args) throws Exception {
            COM.ibm.db2.jdbc.app.DB2Driver drv = new
    COM.ibm.db2.jdbc.app.DB2Driver();
            Properties prop = new Properties();
            prop.put("user", dbUser);
            prop.put("password", dbPassword);
            Connection conn = drv.connect(dbName,prop);
            if (conn == null) System.out.println("connection is null");
            else System.out.println("connection successful");
            conn.setAutoCommit(false);
            conn.close();
            conn = null;
            drv = null;
            System.out.println("done");
        }
    }

    >Newsgroups: comp.lang.java.databases
    >From: David McDivitt <x12code-del@del-yahoo.com>
    >Subject: help creating datasource
    >Date: Thu, 14 Oct 2004 11:09:56 -0500
    >
    >I have made several web apps using struts in Websphere 5.0. For each one I
    >copied a template app having everything I need. We have some batch
    >processing which needs to be done, and instead of using struts I want to
    >make a single standalone class for one of the jobs. The database is IBM DB2.
    >
    >I picked through the struts stuff and copied what seemed to make sense into
    >the class I'm making. I got the runtime error:
    >
    > javax.naming.NoInitialContextException: Cannot instantiate class:
    > COM.ibm.db2.jdbc.app.DB2Driver. Root exception is
    > java.lang.ClassCastException: COM.ibm.db2.jdbc.app.DB2Driver
    >
    >After searching google I found where someone said this is a bug in the IBM
    >driver and it's necessary to unzip db2java.zip into the project.
    >Unfortunately there are four files in the zip file which have a lower case
    >"com" instead of an upper case "COM", and the zip file will not import
    >without errors due to name conflict. So I edited those classes changing each
    >occurrence of com/ibm to COM/ibm and created another zip file which does
    >import OK. If classes are imported they must be placed at Web
    >Content/WEB-INF/classes, but they are not found, and if the project is
    >rebuilt they are deleted. To be used, source must exist at the Java Source
    >portion of the project.
    >
    >I tried placing the repaired zip file at Web Content/WEB-INF/lib. When I
    >attempt to run I get a Windows GPF.
    >
    >I also tried bypassing the context stuff, instantiating the DB2Driver class,
    >and setting properties in that. Unfortunately the DB2Driver class does not
    >have any properties to be set directly, and can only be configured by use of
    >a context object, it would seem.
    >
    >If anyone has an example of how to create an IBM DB2 datasource, connection,
    >and execute an SQL statement, in one single class, I would appreciate help.
    >Thanks


  • Next message: Lionel: "Hibernate and multiple datasources..."

    Relevant Pages

    • help creating datasource
      ... I have made several web apps using struts in Websphere 5.0. ... The database is IBM DB2. ... and setting properties in that. ...
      (comp.lang.java.databases)
    • Struts Help
      ... table using struts in netbeans 5.0. ... private DataSource dataSource; ... String jobtitle; ... public job(String jobid,String jobtitle,String applydate) { ...
      (comp.lang.java.programmer)
    • Cannot load JDBC driver class com.microsoft.jdbcx.sqlserver.SQLServerDataSource
      ... I'm trying to configure a datasource to access a Sql Sever db in a Struts ... I read a lot of tutorials and forums and then I tried to declare the ...
      (comp.lang.java.help)