抗癌新药来了!涉及11个癌种患者,能否成为抗癌成功的”救命药”

抗癌新药来了!涉及11个癌种患者,能否成为抗癌成功的”救命药”,第1张

package comly520db;
import javasqlConnection;
import javasqlDriverManager;
import javasqlPreparedStatement;
import javasqlResultSet;
import javasqlResultSetMetaData;
import javasqlSQLException;
import javasqlStatement;
import javautilEnumeration;
import javautilHashtable;
import javautilList;
import javautilVector;
import javaxnamingContext;
import javaxnamingInitialContext;
import javaxsqlDataSource;
/
mysql数据库 *** 作类。

@author Ryoma

/
public class MySqlOperate implements SqlOperate {
private Connection con;
private String DBname;
private String sql;
/
Mysql数据库初始化包名
/
private String INIT_SQL_CTX = "orggjtmmmysqlDriver";
/
MYSQL数据库服务参数:服务器IP地址和端口
/
private String SQL_SERVICE = "jdbc:mysql://127001:3306autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8";
/
MYSQL数据库参数:系统管理用户
/
private String SQL_SYSTEM_USER = "root";
/
MYSQL数据库参数:系统管理密码
/
private String SQL_SYSTEM_PASSWORD = "123456";
/
初始化链接方法。此方法不需要再使用use Dbname;
/
public MySqlOperate() {
try {
Context ctx = new InitialContext();
if (ctx == null)
throw new Exception("Boom - No Context");
// java:comp/env/jdbc/imabled_mysql 为配置的连接池的jndi名称。
DataSource ds = (DataSource) ctx
lookup("java:comp/env/jdbc/imabled_mysql");
con = dsgetConnection();
} catch (Exception ex) {
exprintStackTrace();
}
}
/
指定库名的连接方法,此方法没有使用连接池,不赞成使用。

@param DBn
/
public MySqlOperate(String DBn) {
try {
ClassforName(thisINIT_SQL_CTX);
} catch (javalangClassNotFoundException e) {
eprintStackTrace();
}
try {
con = DriverManagergetConnection(thisSQL_SERVICE + "/" + DBn,
thisSQL_SYSTEM_USER, thisSQL_SYSTEM_PASSWORD);
DBname = DBn;
} catch (SQLException ex) {
exprintStackTrace();
}
}
public boolean add(String tablename, Hashtable searchdetail) {
Statement stmt = null;
Enumeration key_values = searchdetailkeys();
String key, value;
String temp = (String) key_valuesnextElement();
key = temp;
value = "'" + searchdetailget(temp) + "'";
while (key_valueshasMoreElements()) {
temp = (String) key_valuesnextElement();
key = key + "," + temp;
value = value + "," + "'" + searchdetailget(temp) + "'";
}
try {
useDB();
stmt = concreateStatement();
sql = "insert into " + tablename + " (" + key + ") " + " VALUES ("
+ value + ")";
stmtexecuteUpdate(sql);
return true;
} catch (SQLException ex) {
Systemoutprintln("执行的出错的sql语句:" + sql);
exprintStackTrace();
return false;
} finally {
closeStmt(stmt);
}
}
public boolean batchImport(String tablename, List list, String[] fields)
throws SQLException {
PreparedStatement ps = null;
String key, value;
key = toString(fields);
String[] values = new String[fieldslength];
for (int i = 0; i < valueslength; i++) {
values[i] = "";
}
value = toString(values);
try {
useDB();
consetAutoCommit(false);
Systemoutprintln("insert into " + tablename + " (" + key + ") "
+ " VALUES (" + value + ")");
ps = conprepareStatement("insert into " + tablename + " (" + key
+ ") " + " VALUES (" + value + ")");
String[] tmpData = null;
for (int i = 0; i < listsize(); i++) {
tmpData = (String[]) listget(i);
for (int j = 0; j < fieldslength && j < tmpDatalength; j++) {
pssetString(j + 1, tmpData[j]);
}
psaddBatch();// 添加执行的语句。
}
int[] count = psexecuteBatch();// 批量执行
concommit();
return true;
} catch (SQLException ex) {
throw ex;
} finally {
try {
if (ps != null) {
psclearParameters();
psclose();
ps = null;
}
} catch (SQLException e) {
throw e;
}
}
}
public boolean delete(String tablename, String filter) {
Statement stmt = null;
String value;
try {
useDB();
stmt = concreateStatement();
sql = "delete from " + tablename + " where " + filter;
stmtexecuteUpdate(sql);
return true;
} catch (SQLException e) {
Systemoutprintln("执行的出错的sql语句:" + sql);
eprintStackTrace();
return false;
} finally {
closeStmt(stmt);
}
}
public Hashtable list(String sql) {
Hashtable[] infoList = search(sql);
if (infoList == null || infoListlength < 1)
return null;
return infoList[0];
}
public Hashtable list(String tablename, String id) {
String sql = "select from " + tablename + " where id ='" + id + "'";
return list(sql);
}
public boolean modify(String tablename, Hashtable setdetail, String filter) {
Enumeration key_values = setdetailkeys();
Statement stmt = null;
String value;
String temp = (String) key_valuesnextElement();
value = temp + "='" + setdetailget(temp) + "'";
while (key_valueshasMoreElements()) {
temp = (String) key_valuesnextElement();
value = value + "," + temp + "='" + setdetailget(temp) + "'";
}
try {
useDB();
stmt = concreateStatement();
sql = "update " + tablename + " set " + value + " where " + filter;
int tag = stmtexecuteUpdate(sql);
if (tag == 0)
return false;
else
return true;
} catch (SQLException e) {
Systemoutprintln("执行的出错的sql语句:" + sql);
eprintStackTrace();
return false;
} finally {
closeStmt(stmt);
}
}
public Hashtable[] search(String sql) {
ResultSet rs;
Statement stmt = null;
try {
useDB();
stmt = concreateStatement();
rs = stmtexecuteQuery(sql);
return toHashtableArray(rs);
} catch (SQLException ex) {
Systemoutprintln("执行的出错的sql语句:" + sql);
exprintStackTrace();
return null;
} finally {
closeStmt(stmt);
}
}
public Hashtable[] search(String tablename, String[] fieldname,
String filter) {
return search(tablename, fieldname, filter, "");
}
public Hashtable[] search(String tablename, String[] fieldname,
String filter, String ordergroup) {
ResultSet rs;
Statement stmt = null;
String colname = fieldname[0];
for (int i = 1; i < fieldnamelength; i++) {
colname += "," + fieldname[i];
}
String queryString = "select " + colname + " from " + tablename;
if (!filterequals("")) {
queryString = queryString + " where " + filter;
}
if (!ordergroupequals("")) {
queryString = queryString + " " + ordergroup;
}
return search(sql);
}
/
@return the con
/
public Connection getCon() {
return con;
}
public void close() {
try {
if (con != null)
conclose();
} catch (SQLException e) {
eprintStackTrace();
}
}
/
返回使用的数据库

@return the dBname
/
public String getDBname() {
return DBname;
}
/
设置使用的数据库

@param bname
the dBname to set
/
public void setDBname(String bname) {
DBname = bname;
}
/
返回执行的sql语句

@return the sql
/
public String getSql() {
return sql;
}
/
本方法是为了再没有使用连接池的情况下,首先选择使用的数据库。
/
private void useDB() {
if (DBname != null && DBnameequals("")) {
String query = "use " + DBname;
Statement stmt = null;
try {
stmt = concreateStatement();
stmtexecute(query);
} catch (SQLException e) {
eprintStackTrace();
} finally {
if (stmt != null) {
try {
stmtclose();
} catch (SQLException e) {
eprintStackTrace();
}
}
}
}
}
/
关闭Statement

@param stmt
/
private void closeStmt(Statement stmt) {
if (stmt != null) {
try {
stmtclose();
} catch (SQLException e) {
eprintStackTrace();
}
}
}
/
@param ss
@return
/
private String toString(String[] ss) {
String s = "";
for (int i = 0; i < sslength; i++) {
s += ss[i] + ",";
}
if (sendsWith(","))
s = ssubstring(0, slength() - 1);
return s;
}
/
把ResultSet转换成Hashtable数组 javautilArraysasList 可以把数组转换成List

@param rs
@return
/
private Hashtable[] toHashtableArray(ResultSet rs) {
Vector searchresult = new Vector();
try {
ResultSetMetaData rsmd = rsgetMetaData();
int column = rsmdgetColumnCount();
while (rsnext()) {
Hashtable onerow = new Hashtable();
for (int i = 1; i <= column; i++) {
try {
String columnName = rsmdgetColumnName(i);
String columnValue = rsgetString(columnName);
onerowput(columnName, columnValue);
} catch (Exception e) {
}
}
searchresultadd(onerow);
}
Hashtable[] searchset = new Hashtable[searchresultsize()];
searchresulttoArray(searchset);
return searchset;
} catch (SQLException e) {
eprintStackTrace();
return null;
}
}
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/13437048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-06
下一篇 2023-08-06

发表评论

登录后才能评论

评论列表(0条)

保存