Unix Technical Forum

Anything wrong?

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


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 05:09 PM
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;
}

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 05:09 PM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 05:09 PM
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 05:09 PM
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:45 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com