JDBC.JAVA
package cn.iszt.test.services;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import cn.iszt.test.model.SqlModel;
import cn.iszt.test.suit.load;
public class JDBC {
public static String DBDRIVER;
public static String DBURL;
public static String USERNAME ;
public static String PASSWORD ;
static //数据库连接对象
Connection conn = null;
public void sqlcon(SqlModel sqlmodel) throws Exception {
Properties prop = new Properties();
InputStream in = Object.class.getResourceAsStream("/mysql.properties");
prop.load(in);
DBDRIVER = prop.getProperty("jdbc.driverClassName").trim();
DBURL = sqlmodel.getDBURL();
USERNAME = sqlmodel.getUSERNAME();
PASSWORD = sqlmodel.getPASSWORD();
//数据库连接对象
//Connection conn = null;
//数据库操作对象
//Statement stmt = null;
//1、加载驱动程序
try {
Class.forName(DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//2、连接数据库
//通过连接管理器连接数据库
try {
//在连接的时候直接输入用户名和密码才可以连接
conn = DriverManager.getConnection(DBURL,USERNAME,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
//3、向数据库中插入一条数据
//String sql = "update iszt_message a set a.REVERT_CONTENT=NULL ,a.UPDATE_TIME=NULL,a.`STATUS`='1' where a.MEMBER_ID='132078' and a.ID='51323'";
// try {
// stmt = conn.createStatement();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// //4、执行语句
// try {
// stmt.executeUpdate(sql);
//
// } catch (SQLException e) {
// e.printStackTrace();
// }
}
public Connection getconn() {
return conn;
}
public void setconn(Connection conn) {
SqlDML.conn = conn;
}
public void sqlclose()throws Exception {
//5、关闭操作,步骤相反哈~
try {
//stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}