Anything wrong?

This is a discussion on Anything wrong? within the MySQL Database forums, part of the Database Forums category; Is there anything wrong as follow method to use DdriverManager to get connection in mysql with j2ee? public class DBHandle { ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008
525
 
Posts: n/a
Default Anything wrong?

Is there anything wrong as follow method to use DdriverManager to get
connection in mysql with j2ee?

public class DBHandle {

public synchronized static Connection getConn() throws Exception {
Connection conn = null;
DataSource ds = null;
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/stat");
if (ds != null) {
conn = ds.getConnection();
}
return conn;
}

public static void closeResource(Statement st, ResultSet rs,
Connection cnn) {
...........
}


public static Connection getConnection() throws Exception {
String driver = "com.mysql.jdbc.Driver";
String urlString = "jdbc:mysql://localhost/stat";
String user = "root";
String pwd = "root";
Class.forName(driver);
Connection cnn = DriverManager.getConnection(urlString, user,
pwd);
return cnn;
}

}
Reply With Quote
  #2 (permalink)  
Old 04-16-2008
Peter H. Coffin
 
Posts: n/a
Default Re: Anything wrong?

On Wed, 16 Apr 2008 09:07:27 -0700 (PDT), 525 wrote:
> Is there anything wrong as follow method to use DdriverManager to get
> connection in mysql with j2ee?
>
> public class DBHandle {
>
> public synchronized static Connection getConn() throws Exception {
> Connection conn = null;
> DataSource ds = null;
> Context ctx = new InitialContext();
> ds = (DataSource) ctx.lookup("java:comp/env/jdbc/stat");
> if (ds != null) {
> conn = ds.getConnection();
> }
> return conn;
> }
>
> public static void closeResource(Statement st, ResultSet rs,
> Connection cnn) {
> ...........
> }
>
>
> public static Connection getConnection() throws Exception {
> String driver = "com.mysql.jdbc.Driver";
> String urlString = "jdbc:mysql://localhost/stat";
> String user = "root";
> String pwd = "root";
> Class.forName(driver);
> Connection cnn = DriverManager.getConnection(urlString, user,
> pwd);
> return cnn;
> }
>
> }


I dunno. What did you expect that it would do? What actually happened?

--
Christian Biblical literalists are trusting themselves to an archaic English
translation of a Latin translation of (help me here) Greek? Aramaic? source.
I wouldn't even trust a VCR manual to make it through that intact. - Dr. Dee
Reply With Quote
  #3 (permalink)  
Old 04-16-2008
525
 
Posts: n/a
Default Re: Anything wrong?

On 4月17日, 上午12时50分, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Wed, 16 Apr 2008 09:07:27 -0700 (PDT), 525 wrote:
> > Is there anything wrong as follow method to use DdriverManager to get
> > connection in mysql with j2ee?

>
> > public class DBHandle {

>
> > public synchronized static Connection getConn() throws Exception {
> > Connection conn = null;
> > DataSource ds = null;
> > Context ctx = new InitialContext();
> > ds = (DataSource) ctx.lookup("java:comp/env/jdbc/stat");
> > if (ds != null) {
> > conn = ds.getConnection();
> > }
> > return conn;
> > }

>
> > public static void closeResource(Statement st, ResultSet rs,
> > Connection cnn) {
> > ...........
> > }

>
> > public static Connection getConnection() throws Exception {
> > String driver = "com.mysql.jdbc.Driver";
> > String urlString = "jdbc:mysql://localhost/stat";
> > String user = "root";
> > String pwd = "root";
> > Class.forName(driver);
> > Connection cnn = DriverManager.getConnection(urlString, user,
> > pwd);
> > return cnn;
> > }

>
> > }

>
> I dunno. What did you expect that it would do? What actually happened?
>
> --
> Christian Biblical literalists are trusting themselves to an archaic English
> translation of a Latin translation of (help me here) Greek? Aramaic? source.
> I wouldn't even trust a VCR manual to make it through that intact. - Dr. Dee- 隐藏被引用文字 -
>
> - 显示引用的文字 -


can the mysql connector/j 5.0 match with mysql
5.0.18,tomcat5.5.25,jdk1.5.?

also,what 's the different bewteen "org.gjt.mm.mysql.Driver" and
"com.mysql.jdbc.Driver"? thus the code above " String driver =
"com.mysql.jdbc.Driver"; " right?
Reply With Quote
  #4 (permalink)  
Old 04-17-2008
Peter H. Coffin
 
Posts: n/a
Default Re: Anything wrong?

On Wed, 16 Apr 2008 10:36:21 -0700 (PDT), 525 wrote:
> On 4??17??, ????12??50??, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>> On Wed, 16 Apr 2008 09:07:27 -0700 (PDT), 525 wrote:
>> > Is there anything wrong as follow method to use DdriverManager to get
>> > connection in mysql with j2ee?

>>
>> > public class DBHandle {

>>
>> > public synchronized static Connection getConn() throws Exception {
>> > Connection conn = null;
>> > DataSource ds = null;
>> > Context ctx = new InitialContext();
>> > ds = (DataSource) ctx.lookup("java:comp/env/jdbc/stat");
>> > if (ds != null) {
>> > conn = ds.getConnection();
>> > }
>> > return conn;
>> > }

>>
>> > public static void closeResource(Statement st, ResultSet rs,
>> > Connection cnn) {
>> > ...........
>> > }

>>
>> > public static Connection getConnection() throws Exception {
>> > String driver = "com.mysql.jdbc.Driver";
>> > String urlString = "jdbc:mysql://localhost/stat";
>> > String user = "root";
>> > String pwd = "root";
>> > Class.forName(driver);
>> > Connection cnn = DriverManager.getConnection(urlString, user,
>> > pwd);
>> > return cnn;
>> > }

>>
>> > }

>>
>> I dunno. What did you expect that it would do? What actually happened?
>>
>> --
>> Christian Biblical literalists are trusting themselves to an archaic English
>> translation of a Latin translation of (help me here) Greek? Aramaic? source.
>> I wouldn't even trust a VCR manual to make it through that intact. - Dr. Dee- ?????????????? -
>>
>> - ?????????????? -

>
> can the mysql connector/j 5.0 match with mysql
> 5.0.18,tomcat5.5.25,jdk1.5.?


I can't find anything handy that says it doesn't.

> also,what 's the different bewteen "org.gjt.mm.mysql.Driver" and
> "com.mysql.jdbc.Driver"? thus the code above " String driver =
> "com.mysql.jdbc.Driver"; " right?


"org.gjt.mm.mysql.Driver" is much earlier, and may or may not work with
later versions of MySQL. It's no longer distributed and has been
replaced by "com.mysql.jdbc.Driver".

--
16 megs in a '95 box! Yo Ho Ho and a battle of RAM!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0