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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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; } } |
| |||
| 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 |
| |||
| 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? |
| ||||
| 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! |