java jdbc
2015-12-26 00:00
555 查看
摘要: java jdbc
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcUtils {
private static String url = "jdbc:mysql://localhost:3306/stswdb?useUnicode=true&characterEncoding=utf-8";
private static String user = "root";
private static String pwd = "";
private static String driverName = "com.mysql.jdbc.Driver";
static {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, pwd);
}
public void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null)
rs.close();
if (st != null)
st.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcUtils {
private static String url = "jdbc:mysql://localhost:3306/stswdb?useUnicode=true&characterEncoding=utf-8";
private static String user = "root";
private static String pwd = "";
private static String driverName = "com.mysql.jdbc.Driver";
static {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, pwd);
}
public void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null)
rs.close();
if (st != null)
st.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
相关文章推荐
- java基础:String
- JAVA基础之正则表达式
- Java基础之时间
- Java基础之Json
- 华为机考Java版
- 设计模式——单例模式 Java源代码
- 团队开发之:eclipse自动格式化代码formatter使用方式
- 命令模式
- 团队开发之:eclipse注释模版使用方式
- 2015/12/25 ① 图灵测试 ② 安装jdk出现的问题 ③ 配置环境变量
- java中properties类的使用
- javaMap
- Log4j日志在java项目中的使用(附工程源码)
- Log4j日志在java项目中的使用(附工程源码)
- Spring依赖注入
- Java中的引用
- eclipse+spket+Extjs4开发环境搭建
- JavaIO流之了解IO流
- ubuntu配置jdk环境
- 求eclipse java heap space 问题解决方案