📄 dbconnection.java
字号:
package com.cn.db.sqlserver;
//*************************************
/*
* Connection封装类
* @author: 祝磊
* @version: 2005.03.18
*/
//******************************************
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.PreparedStatement;
public class DBConnection {
private Connection connection=null;
private String url="";
private long timestamp=0;
public DBConnection(Connection connection,String url)
{
this.connection=connection;
this.url=url;
this.timestamp=System.currentTimeMillis();
}
public Connection getConnection()
{
return connection;
}
public long gettimestamp()
{
return timestamp;
}
public void close()//关闭连接
{
Connection conn=getConnection();
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
public void commit()//提交一个事物
{
try {
connection.commit();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
public void rollnack()//事物回滚
{
try {
connection.rollback();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
public void setAutoCommit(boolean b)//设置是否回滚
{
try {
connection.setAutoCommit(b);
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
public Statement createStatement()//生成Statement
{
Statement stat=null;
try {
stat = connection.createStatement();
}
catch (SQLException ex) {
ex.printStackTrace();
}
return stat;
}
public PreparedStatement preparedStatement(String sql)
{
PreparedStatement stat=null;
try {
stat = connection.prepareStatement(sql);
}
catch (SQLException ex) {
ex.printStackTrace();
}
return stat;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -