Java数据库连接池 http://jxhandyanxue.uu1001.com这里面能够找到你想要的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那上边没有呀我想要用Java类写的 这样就可以连接任何数据库 还可以重用 package com.fenye;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class ConnectionMessage { private Connection conn = null; public ConnectionMessage(){ this("root","admin"); } public ConnectionMessage(String username,String password){ String className = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test"; try { Class.forName(className); conn = DriverManager.getConnection(url,username,password); System.out.println("数据库连接成功"); } catch (ClassNotFoundException e) { System.out.println("数据库连接失败"); // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { System.out.println("数据库连接失败"); // TODO Auto-generated catch block e.printStackTrace(); } } public Connection getConnection(){ return conn; } public static void close(ResultSet rs,Statement st,PreparedStatement ps,CallableStatement cs,Connection conn){ try { if(rs!=null){ rs.close(); } if(st!=null){ st.close(); } if(ps!=null){ ps.close(); } if(cs!=null){ cs.close(); } if(conn!=null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}这个是连接mysql的连接类~不过我不是大哥,嘎嘎 JAVA控制针式打印机的问题 JAVA中 split 使用的疑惑 hibernate + extJs3.1分页问题 散分,本人想自己做个网站,请大家给些建议。 请问下面的代码为什么要用synchronized 关于参数传递的问题 关于在tomcat下两个应用程序互相访问的问题 这个问题没人会 求助:myeclipse中缺少Myeclipse Visual HTML editor编辑器 急!!!struts中ActionForm类的属性类型的设置??? 请教FCKeditor编辑器的的问题 请问学习了Java EE 5的基础教程后怎样拓展、深入研究?
我想要用Java类写的 这样就可以连接任何数据库
还可以重用
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class ConnectionMessage {
private Connection conn = null;
public ConnectionMessage(){
this("root","admin");
}
public ConnectionMessage(String username,String password){
String className = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
try {
Class.forName(className);
conn = DriverManager.getConnection(url,username,password);
System.out.println("数据库连接成功");
} catch (ClassNotFoundException e) {
System.out.println("数据库连接失败");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
System.out.println("数据库连接失败");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Connection getConnection(){
return conn;
}
public static void close(ResultSet rs,Statement st,PreparedStatement ps,CallableStatement cs,Connection conn){
try {
if(rs!=null){
rs.close();
}
if(st!=null){
st.close();
}
if(ps!=null){
ps.close();
}
if(cs!=null){
cs.close();
}
if(conn!=null){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}这个是连接mysql的连接类~
不过我不是大哥,嘎嘎