Eric,
I'd suggest switching to MySQL or PostgresSQL databases. There are Type 4
drivers available for both. Is this a commercial site or just for
development purposes? What application server are you using?

-Richard


-----Original Message-----
From: Zhou, Qin (Eric) [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 12, 2003 2:54 PM
To: 'Struts Users Mailing List'
Subject: RE: Connect close the DB connection in Form Action


Richard

I am not experienced with DB access. Which driver do you suggest? I am
reading from ACCESS. Can you provide some sample code for initilizing the
driver. 

Thanks

Eric Zhou

-----Original Message-----
From: Yee, Richard K,,DMDCWEST [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 12, 2003 3:35 PM
To: 'Struts Users Mailing List'
Subject: RE: Connect close the DB connection in Form Action


Eric,
It is generally not recommended to use the JDBC-ODBC bridge driver. There
are several bugs in the driver and it doesn't perform as well as a type 4
driver. What DB are you using? Also, you don't have to register the driver
every time. Put the Class.forName call in a static initializer or somewhere
else that will only get called once. It's also a better practice to use a
pooled DataSource.

Regards,

Richard

-----Original Message-----
From: Zhou, Qin (Eric) [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 12, 2003 12:36 PM
To: 'Struts Users Mailing List'
Subject: Connect close the DB connection in Form Action


I have the following code in my Form file. The methods retrieve data from
access DB to populated the two drop down boxes. But con.close() generates
'General error' exception? Any help is appreciated.


        /**
                 * Return a list of week ending date
                 * @return      ArrayList       List of week ending date
         */
        
        private static ArrayList getWeekEndingDateList()
        {
                Connection con = null;
                statement stmt = null;
                ResultSet rs = null;
                ArrayList weekEndingDate = new ArrayList();

                try {
                        //Register driver:
        
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); 
                        //Establish a connection to given database URL:
                        con =
DriverManager.getConnection("jdbc:odbc:Timesheet","","");
                        //Create a Statement object for sending SQL
statements to the database:
                        stmt = con.createStatement();
   
                        String sql = "select * from Weeks order by
Wk_Ending";
;                       
                                rs = stmt.executeQuery(sql);

                                System.out.println("SQL = " + sql);

                        while (rs.next()) {

                                String weekNum = rs.getString("Wk_Num");
                                String wkEndingDate =
rs.getString("Wk_Ending");
                                //System.out.println("Week Num = " +
weekNum);
                                //System.out.println("wkEndingDate = " +
wkEndingDate);

                                weekEndingDate.add(new
LabelValueBean(wkEndingDate, wkEndingDate));
                        
                        }

                } catch(Exception e) 
                        { 
                                System.out.println(e.toString()); 
                        }
                        finally {
                                //Close the connection:
                                try {
                                                if (rs != null) rs.close();
                                                if (stmt != null)
stmt.close();
                                                if (con != null)
con.close();
        
                                } catch (SQLException e) {
                                        System.out.println(e.toString()); 
                                }
                        }


                return weekEndingDate;
        }


        /**
                 * Return a list of work category
                 * @return      ArrayList       List of work category
         */
        
        private static ArrayList getWorkCategoryList()
        {
                Connection con = null;
                Statement stmt = null;
                ResultSet rs = null;
                ArrayList workCategory = new ArrayList();

                try {
                        //Register driver:
        
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); 
                        //Establish a connection to given database URL:
                        con =
DriverManager.getConnection("jdbc:odbc:Timesheet","","");
                        //Create a Statement object for sending SQL
statements to the database:
                        stmt = con.createStatement();
   
                        String sql = "select * from workCategory";
;                       
                                rs = stmt.executeQuery(sql);

                                System.out.println("SQL = " + sql);

                        while (rs.next()) {

                                String categoryNum =
rs.getString("Cat_Num");
                                String workCategories =
rs.getString("Category");
                                //System.out.println("Category Num = " +
categoryNum);
                                //System.out.println("work category = " +
workCategories);

                                workCategory.add(new
LabelValueBean(workCategories, workCategories));
                        
                        }

                } catch(Exception e) 
                        { 
                                System.out.println(e.toString()); 
                        }
                        finally {
                                //Close the connection:
                                try {
                                                if (rs != null) rs.close();
                                                if (stmt != null)
stmt.close();
                                                if (con != null)
con.close();
        
                                } catch (SQLException e) {
                                        System.out.println(e.toString()); 
                                }
                        }


                return workCategory;
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to