PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Anything wrong?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Anything wrong?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/04/2008, 17h07   #1
525
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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;
}

}
  Réponse avec citation
Vieux 16/04/2008, 17h50   #2
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 ( me here) Greek? Aramaic? source.
I wouldn't even trust a VCR manual to make it through that intact. - Dr. Dee
  Réponse avec citation
Vieux 16/04/2008, 18h36   #3
525
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 ( 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?
  Réponse avec citation
Vieux 17/04/2008, 13h26   #4
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 ( 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!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h34.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11610 seconds with 12 queries