Subject: Re: Why use DAOFactory? Can't get connection
From: Vic C <[EMAIL PROTECTED]>
 ===
news://news.basebeans.com:[EMAIL PROTECTED]


above is the conculsion by the same poster.

(Friday OT: I was suposed to work on a paper for a client today. Can't 
wait for the Laker game in a bit where Yugos win. I propose that from 
now on, who ever posts most on a Friday be called the woden nickel (the 
5th day) next week by the Struts mail list, as a sign of shame. At least 
next week I will be teching and not on this list.)

Damien VIEL wrote:
> Hi,
> 
> Maybe this Thread will help you.
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg30193.html
> 
> Regards
> Dams
> ----- Original Message -----
> From: "Chen, Dean (Zhun)" <[EMAIL PROTECTED]>
> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
> Sent: Friday, May 24, 2002 10:37 PM
> Subject: Why use DAOFactory? Can't get connection
> 
> 
> 
>>Hi,
>>
>>I'm running into some issue with implementing a DAO. I see posts that some
>>design use a DaoFactory, I don't understand the benefit of it. Is it
>>possible to obtain connections instead of using a Factory?
>>
>>For example:
>>
>>In my XXXAction class, I have
>>
>>BeanDao beandao = new BeanDao();
>>beandao.executeQuery(sql, VO);
>>
>>
>>The BeanDao extends BaseDao, which has the following, where name is
>>"java:comp/env/jdbc/myDatasource"
>>
>>protected Connection getConnection(String name) throws
>>DatabaseUnavailableException{
>>Connection conn = null;
>>try {
>>InitialContext ic = new InitialContext();
>>
>>DataSource ds = (DataSource) ic.lookup(name);
>>
>>if (ds==null)
>>throw new
>>DatabaseUnavailableException("Cannot connect to database: "+name);
>>
>>try {
>>conn = ds.getConnection();
>>}
>>catch (SQLException e) {
>>// log
>>e.printStackTrace();
>>}
>>}
>>catch (NamingException e) {
>>//e.printStackTrace();
>>}
>>return conn;
>>}
>>
>>This however, doesn't work, I get this error:
>>
>>java.sql.SQLException: No suitable driver
>>        at java.sql.DriverManager.getDriver(DriverManager.java:243)
>>        at
>>tyrex.jdbc.xa.EnabledDataSource.getConnection(EnabledDataSource.java:233)
>>        at
>>tyrex.jdbc.xa.EnabledDataSource.getConnection(EnabledDataSource.java:204)
>>
>>The even odder thing is that instead of
>>DataSource ds = (DataSource) ic.lookup(name);
>>I explicitly call using
>>DataSource ds = (DataSource)
>>ic.lookup("java:comp/env/jdbc/myDatasource");
>>
>>I don't get the above SQL error, instead, I get a
>>java.lang.NullPointerException when I try to use the connection.
>>
>>I'm using Tomcat 4.03 with Struts 1.1 + Sybase jconn2.jar
>>
>>If anyone can shed some light on this, I'd really appreciate it. I looked
> 
> up
> 
>>on the tomcat mailing-list archive and didn't see any solutions.
>>
>>Thanks,
>>
>>Dean Chen
>>
>>
>>
>>--
>>To unsubscribe, e-mail:
> 
> <mailto:[EMAIL PROTECTED]>
> 
>>For additional commands, e-mail:
> 
> <mailto:[EMAIL PROTECTED]>
> 
>>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


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

Reply via email to