一个导库的类DataMove
来源:互联网 发布:arcgis10.2 mac版 编辑:程序博客网 时间:2024/05/16 09:19
package com.tzsw.hjyweb.admin;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import com.tzsw.hjyweb.db.*;
/**
* <p> 数据转移,从业务系统到网站业务系统 </p>
* @version 1.0
*/
public class DataMove {
String logfile="";
static DataSource dataSource;
String oprTable="";
//boolean skip=false;
public DataMove() {
try {
dataSource=TopcheerDataSource.getDataSource();
} catch (Exception e){
System.out.println(e.getMessage());
}
}
public void writeLog(String writeStr){
try{
RandomAccessFile out=new RandomAccessFile(new File(logfile),"rw");
out.seek(out.length());
out.write(writeStr.getBytes());
out.write("/n".getBytes());
out.close();
} catch (FileNotFoundException e){
System.out.println(e.getMessage());
} catch (IOException e){
System.out.println(e.getMessage());
}
}
public String readLog(){
StringBuffer sb=new StringBuffer();
try{
BufferedReader in=new BufferedReader(new FileReader(new File(logfile)));
while (in.ready()){
sb.append(in.readLine());
//sb.append("/n");
sb.append("<br>");
}
in.close();
} catch (FileNotFoundException e){
System.out.println(e.getMessage());
return "日志文件还没有建立或者已经破坏!";
} catch (IOException e){
System.out.println(e.getMessage());
return "读日志文件的过程中发生错误!";
}
return sb.toString();
}
public void setLogfile(String logfile){
this.logfile=logfile;
}
public void movePersonalIn(){
try{
Connection conn=dataSource.getConnection();
Statement statement=conn.createStatement();
conn.setAutoCommit(false);
try{
int labour=0,seekjob=0,resume=0,temp_labour=0,temp_seekjob=0,
temp_resume=0,web_users=0,seekjobadvert=0,photo=0;
labour=statement.executeUpdate(labourIn());
//wzq add 2003-09-25
statement.executeUpdate(seekjobIn_Del());
seekjob=statement.executeUpdate(seekjobIn());
resume=statement.executeUpdate(resumeIn());
photo=statement.executeUpdate(photoIn());
conn.commit();
StringBuffer sb=new StringBuffer();
sb.append("个人用户表导入情况如下:");
sb.append(new java.util.Date().toString());
sb.append("/n");
sb.append("/tLabour表成功导入了");
sb.append(labour);
sb.append("条记录./n");
sb.append("/tSeekjob表成功导入了");
sb.append(seekjob);
sb.append("条记录./n");
sb.append("/tResume表成功导入了");
sb.append(resume);
sb.append("/tPhoto表成功导入了");
sb.append(photo);
sb.append("条记录./n");
writeLog(sb.toString());
} catch (SQLException e){
conn.rollback();
StringBuffer sb=new StringBuffer();
sb.append("个人用户导入情况如下:");
sb.append(new java.util.Date().toString());
sb.append("/n");
sb.append("/t在导入表");
sb.append(oprTable);
sb.append("时发生错误!");
sb.append(new java.util.Date().toString());
sb.append("/n");
writeLog(sb.toString());
e.printStackTrace();
}
statement.close();
conn.close();
} catch (SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public void moveCompanyIn(){
try{
Connection conn=dataSource.getConnection();
Statement statement=conn.createStatement();
conn.setAutoCommit(false);
try{
int company=0,employer=0,want=0,temp_company=0,temp_employer=0,
temp_want=0,web_company_user=0,companyadvert=0;
company=statement.executeUpdate(companyIn());
//wzq add 2003-09-25
statement.executeUpdate(employerIn_Del());
employer=statement.executeUpdate(employerIn());
want=statement.executeUpdate(wantIn());
conn.commit();
StringBuffer sb=new StringBuffer();
sb.append("单位用户表导入情况如下:");
sb.append(new java.util.Date().toString());
sb.append("/n");
sb.append("/tCompany表成功导入了");
sb.append(company);
sb.append("条记录./n");
sb.append("/tEmployer表成功导入了");
sb.append(employer);
sb.append("条记录./n");
sb.append("/tWant表成功导入了");
sb.append(want);
sb.append("条记录./n");
writeLog(sb.toString());
} catch (SQLException e){
conn.rollback();
StringBuffer sb=new StringBuffer();
sb.append("单位用户导入情况如下:");
sb.append(new java.util.Date().toString());
sb.append("/n");
sb.append("/t在导入表");
sb.append(oprTable);
sb.append("时发生错误!");
sb.append(new java.util.Date().toString());
sb.append("/n");
writeLog(sb.toString());
e.printStackTrace();
// System.out.println(e.getMessage());
}
statement.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
}
private String labourIn(){
oprTable="Labour";
String sql="insert into labour "+
"(select * from labour@usremlmnew "+
"where labidno in "+
"(select labidno from labour@usremlmnew "+
"minus select labidno from labour))";
return sql;
}
private String seekjobIn_Del(){
oprTable="Seekjob";
String sql="delete from seekjob where sjbflag='Y' ";
return sql;
}
private String seekjobIn(){
oprTable="Seekjob";
String sql="insert into seekjob(sjbno,sjbidno,sjbname,sjbpostreqcd1,"+
"sjbpostreqcd2,sjbpostreqcd3,sjbemptpreq1,sjbemptpreq2,"+
"sjbemptpreq3,sjbminsalreq,sjbaddreq,sjbturnreq1,sjbturnreq2,sjbturnreq3,sjbvalid,sjbnote,sjbiscopy,"+
"sjbstate,sjbrectime,sjboprdt,sjboprcd,insertdt,insertuserid,insertdeptid,"+
"qnote0,qnote1,qnote2,mnote0,mnote1,mnote2,dnote0,dnote1,dnote2,sjbflag)"+
"(select sjbno,sjbidno,sjbname,sjbpostreqcd1,sjbpostreqcd2,sjbpostreqcd3,sjbemptpreq1,sjbemptpreq2,"+
"sjbemptpreq3,sjbminsalreq,sjbaddreq,sjbturnreq1,sjbturnreq2,sjbturnreq3,sjbvalid,sjbnote,sjbiscopy,"+
"sjbstate,sjbrectime,sjboprdt,sjboprcd,sysdate,insertuserid,insertdeptid,"+
"qnote0,qnote1,qnote2,mnote0,mnote1,mnote2,dnote0,dnote1,dnote2,'Y' "+
"from seekjob@usremlmnew where sjbno in (select sjbno from seekjob@usremlmnew "+
"where sjbstate='WT' and sjbweb='Y' and sjbvalid+1>sysdate minus select sjbno from seekjob))";
return sql;
}
private String resumeIn(){
oprTable="Resume";
String sql="insert into resume "+
"(select * from resume@usremlmnew "+
"where rsmno in "+
"(select rsmno from resume@usremlmnew "+
"minus select rsmno from resume))";
return sql;
}
private String companyIn(){
oprTable="company";
String sql="insert into company( "+
"cmpcmpcd,cmpname,cmptype,cmpectype,cmpusccd," +
"cmpclass,cmptrade,cmpmother,cmprange,cmpregion," +
"cmpscale,cmpinvarea,cmpinvtl,cmplglname,cmptel," +
"cmplnkman,cmplnkmanadd,cmppstcd,cmpregadd,cmpregrmb," +
"cmpregfc,cmpfctype,cmpflag,cmpismember,cmpcredit," +
"cmpifcons,cmpbank,cmpacctno,cmpstartdt,cmpenddt," +
"cmpinittown,cmpinitfarm,cmpcmpregdt,cmpregcd," +
"cmpregdt,cmpoprcd,cmpoprdt,cmplicence,cmpnote)" +
"(select "+
"cmpcmpcd,cmpname,cmptype,cmpectype,cmpusccd," +
"cmpclass,cmptrade,cmpmother,cmprange,cmpregion," +
"cmpscale,cmpinvarea,cmpinvtl,cmplglname,cmptel," +
"cmplnkman,cmplnkmanadd,cmppstcd,cmpregadd,cmpregrmb," +
"cmpregfc,cmpfctype,cmpflag,cmpismember,cmpcredit," +
"cmpifcons,cmpbank,cmpacctno,cmpstartdt,cmpenddt," +
"cmpinittown,cmpinitfarm,cmpcmpregdt,cmpregcd," +
"cmpregdt,cmpoprcd,cmpoprdt,cmplicence,cmpnote " +
" from company@usremlmnew "+
"where cmpcmpcd in "+
"(select cmpcmpcd from company@usremlmnew "+
"minus select cmpcmpcd from company))";
return sql;
}
private String employerIn_Del(){
oprTable="employer";
String sql="delete from employer where empflag='Y'";
return sql;
}
private String employerIn(){
oprTable="employer";
String sql="insert into employer(empno,empauthor,empcmpcd,empcmpname,emplink,emptel,emplnkpc,emplnkadd,emplnkway,empwkadd,"+
"empwkway,empemptp,emptype,emptimddt,emppitchadd,empobj,empregion,empwkplc,"+
"empappdt,empappenddt,empaddt,empadenddt,empisrush,empisnormal,empnote,empstatus,"+
"emptype1,empplacard,empoprdt,empoprcd,insertdt,insertuserid,insertdeptid,"+
"qnote0,qnote1,qnote2,mnote0,mnote1,mnote2,dnote0,dnote1,dnote2,empflag)"+
"(select empno,empauthor,empcmpcd,empcmpname,emplink,emptel,emplnkpc,emplnkadd,emplnkway,empwkadd,"+
"empwkway,empemptp,emptype,emptimddt,emppitchadd,empobj,empregion,empwkplc,"+
"empappdt,empappenddt,empaddt,empadenddt,empisrush,empisnormal,empnote,empstatus,"+
"emptype1,empplacard,empoprdt,empoprcd,sysdate,insertuserid,insertdeptid,"+
"qnote0,qnote1,qnote2,mnote0,mnote1,mnote2,dnote0,dnote1,dnote2,'Y' "+
"from employer@usremlmnew where empno in (select empno from employer@usremlmnew "+
"where empappenddt+1>sysdate and empweb='Y' and (empstatus='UU' or empstatus='US') and empweb='Y' "+
"minus select empno from employer)) ";
return sql;
}
private String wantIn(){
oprTable="want";
String sql="insert into want(select * from want@usremlmnew where wntempno in "+
"(select empno from employer where empflag='Y'))";
return sql;
}
private String photoIn(){
oprTable="photo";
String sql="INSERT INTO photo(SELECT * FROM photo@usremlmnew where phoidno in "+
"(select phoidno from photo@usremlmnew minus select phoidno from photo))";
return sql;
}
public static void main(String[] args){
DataMove app=new DataMove();
app.movePersonalIn();
// app.moveCompanyIn();
app.setLogfile("fdsaf");
app.writeLog("中国");
app.writeLog("new2");
System.out.println(app.readLog());
}
}
================================================================
package com.tzsw.hjyweb.db;
import java.sql.Connection;
import java.sql.Driver;
import java.util.Properties;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class DbConnect {
public DbConnect() {
}
public static Connection getConnect() {
try {
Driver driver=(Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.2.3.210:1521:hzjy";
Properties p=new Properties();
p.setProperty("user","hjyweb");
p.setProperty("password","oracle");
Connection conn = driver.connect(url,p);
return conn;
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
public static void main(String[] args)throws Exception {
DbConnect dbTest=new DbConnect();
System.out.println("**"+dbTest);
}
}
=======================================================================
package com.tzsw.hjyweb.db;
import com.tzsw.hjyweb.db.TopcheerDynamicUpdate;
import com.tzsw.hjyweb.db.TopcheerQuery;
public class DoSqlOperate{
protected boolean updateStatus=false;
protected String exceptionMessage="";
public DoSqlOperate(){
}
public boolean hasSame(String sql){
boolean result=false;
TopcheerQuery topcheerQuery=new TopcheerQuery();
result=topcheerQuery.hasRecord(sql);
topcheerQuery.close();
return result;
}
public boolean insert(String sql){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
dynamicUpdate.doUpdate(sql);
updateStatus=true;
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
System.out.println(updateStatus);
return updateStatus;
}
public boolean insert(String sql,String[] para){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
dynamicUpdate.doUpdate(sql,para);
updateStatus=true;
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
return updateStatus;
}
public boolean update(String sql){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
int count=dynamicUpdate.doUpdate(sql);
if (count>0)
updateStatus=true;
else{
updateStatus=false;
exceptionMessage="要更新的记录不存在.";
}
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
return updateStatus;
}
public boolean update(String sql,String[] para){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
int count=dynamicUpdate.doUpdate(sql,para);
if (count>0)
updateStatus=true;
else{
updateStatus=false;
exceptionMessage="要更新的记录不存在.";
}
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
return updateStatus;
}
public boolean delete(String sql){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
int count=dynamicUpdate.doUpdate(sql);
if (count>0)
updateStatus=true;
else{
updateStatus=false;
exceptionMessage="要删除的记录不存在.";
}
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
return updateStatus;
}
public boolean delete(String sql,String[] para){
TopcheerDynamicUpdate dynamicUpdate=new TopcheerDynamicUpdate();
try{
int count=dynamicUpdate.doUpdate(sql,para);
if (count>0)
updateStatus=true;
else{
updateStatus=false;
exceptionMessage="要删除的记录不存在.";
}
} catch (Exception e){
updateStatus=false;
exceptionMessage=e.getMessage();
}
dynamicUpdate.close();
return updateStatus;
}
public String getExceptionMessage(){
return exceptionMessage;
}
public void setExceptionMessage(String exceptionMessage){
this.exceptionMessage=exceptionMessage;
}
}
=========================================================
package com.tzsw.hjyweb.db;
import java.sql.Connection;
import java.sql.Driver;
import java.util.Properties;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class SQLConnect {
public SQLConnect() {
}
public static Connection getConnect() {
try {
Driver driver=(Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://192.2.3.122:1433;DatabaseName=szldbz";
Properties p=new Properties();
p.setProperty("user","sa");
p.setProperty("password","1");
Connection conn = driver.connect(url,p);
// Connection conn = java.sql.DriverManager.getConnection(url,p);
// System.out.println(conn+"##");
return conn;
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public static void main(String[] args)throws Exception {
// SQLConnect dbTest=new SQLConnect();
System.out.println(SQLConnect.getConnect()+"**");
}
}
============================================================
package com.tzsw.hjyweb.db;
public interface SqlOperate{
boolean hasSame(String sql);
boolean insert(String sql);
boolean insert(String sql,String[] para);
boolean update(String sql);
boolean update(String sql,String[] para);
boolean delete(String sql);
boolean delete(String sql,String[] para);
Info query(String sql);
String getExceptionMessage();
void setExceptionMessage(String exceptionMessage);
}
===========================================
package com.tzsw.hjyweb.db;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Driver;
import java.sql.DatabaseMetaData;
import java.sql.SQLWarning;
import java.util.Properties;
public class TopcheerConnection{
final int TRANSACTION_NONE=Connection.TRANSACTION_NONE;
final int TRANSACTION_READ_COMMITTED=Connection.TRANSACTION_READ_COMMITTED;
final int TRANSACTION_READ_UNCOMMITTED=Connection.TRANSACTION_READ_UNCOMMITTED;
final int TRANSACTION_REPEATABLE_READ=Connection.TRANSACTION_REPEATABLE_READ;
final int TRANSACTION_SERIALIZABLE=Connection.TRANSACTION_SERIALIZABLE;
private Connection connection;
public TopcheerConnection(){
}
public void setConnection() throws SQLException,Exception{
//connection=TopcheerDataSource.getDataSource().getConnection();
connection=DbConnect.getConnect();
}
public void setConnection(final String sdriver,final String url,
final String user,final String password)
throws Exception{
try{
Driver driver = (Driver)Class.forName(sdriver).newInstance();
Properties p = new Properties();
p.put("user", user);
p.put("password", password);
connection = driver.connect(url, p);
} catch(ClassNotFoundException e){
throw e;
} catch(IllegalAccessException e){
throw e;
} catch (SQLException e){
throw e;
} catch (Exception e){
throw e;
}
}
public Connection getConnection(){
return connection;
}
public void setAutoCommit(boolean b) throws SQLException{
connection.setAutoCommit(b);
}
public void commit() throws SQLException{
connection.commit();
}
public void rollback() throws SQLException{
connection.rollback();
}
public void releaseConnection() throws SQLException{
if(connection!=null&&!connection.isClosed())
connection.close();
}
public String getSQLWarning() throws SQLException{
SQLWarning sqlwarnings=connection.getWarnings();
StringBuffer sb_warnings=new StringBuffer();
while (sqlwarnings!=null){
sb_warnings.append("error happened./n");
sb_warnings.append(" Message is "+sqlwarnings.getMessage()+"/n");
sb_warnings.append(" SQLState is "+sqlwarnings.getSQLState()+"/n");
sb_warnings.append(" ErrorCode is "+sqlwarnings.getErrorCode()+"/n");
sb_warnings.append("Continuing....");
sqlwarnings=sqlwarnings.getNextWarning();
}
return sb_warnings.toString();
}
public void setTransactionIsolation(int level) throws SQLException{
DatabaseMetaData dbMetaData=connection.getMetaData();
if (dbMetaData.supportsTransactionIsolationLevel(level))
connection.setTransactionIsolation(level);
}
}
================================================================
package com.tzsw.hjyweb.db;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.ConnectionPoolDataSource;
import com.tzsw.hjyweb.pub.JNDINames;
public class TopcheerConnectionPoolDataSource{
private static ConnectionPoolDataSource pooldataSource=null;
private static Context context=null;
public TopcheerConnectionPoolDataSource(){
}
public final static ConnectionPoolDataSource getConnectionPoolDataSource() throws Exception{
try{
if (pooldataSource==null){
pooldataSource=(ConnectionPoolDataSource)getInitContext().lookup(JNDINames.HJYWEB_POOL_DATASOURCE);
}
} catch(NamingException e){
throw e;
} catch(Exception e){
throw e;
}
return pooldataSource;
}
public final static Context getInitContext() throws Exception{
try{
if (context==null){
context=new InitialContext();
}
} catch(NamingException e){
throw e;
} catch(Exception e){
throw e;
}
return context;
}
}
============================================================
package com.tzsw.hjyweb.db;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import com.tzsw.hjyweb.pub.JNDINames;
public class TopcheerDataSource{
private static DataSource dataSource=null;
private static Context context=null;
public TopcheerDataSource(){
}
public final static DataSource getDataSource() throws Exception{
try{
if (dataSource==null){
dataSource=(DataSource)getInitContext().lookup(JNDINames.HJYWEB_POOL_DATASOURCE);
}
}catch(NamingException e){
throw e;
}
return dataSource;
}
public final static Context getInitContext() throws Exception{
try{
if (context==null){
context=new InitialContext();
}
} catch(NamingException e){
throw e;
} catch(Exception e){
throw e;
}
return context;
}
}
===========================================================
package com.tzsw.hjyweb.db;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.tzsw.hjyweb.exception.*;
import com.tzsw.hjyweb.pub.Constants;
public class TopcheerDynamicQuery{
private boolean debug=false;
private TopcheerConnection topcheerConnection;
private TopcheerPreparedStatement topcheerPreparedStatement;
public TopcheerDynamicQuery(){
try{
topcheerConnection=new TopcheerConnection();
topcheerPreparedStatement=new TopcheerPreparedStatement();
setCurrentConnection();
} catch(Exception e){
e.printStackTrace();
}
}
//一次以上就要close,否则游标没有释放
public ResultSet doQuery(String sql){
ResultSet rs=null;
try{
rs=operate(sql,null);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return rs;
}
public ResultSet doQuery(String sql,String[] pstatementParameters){
ResultSet rs=null;
try{
return operate(sql,pstatementParameters);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return rs;
}
public String doQueryOne(String sql){
String result="";
try{
ResultSet rs=operate(sql,null);
if (rs==null||!rs.next()) return result;
result=rs.getString(1);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return result;
}
public String doQueryOne(String sql,String[] pstatementParameters){
String result="";
try{
ResultSet rs=operate(sql,pstatementParameters);
if (rs==null||!rs.next()) return result;
return rs.getString(1);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return result;
}
public boolean hasRecord(String sql){
boolean found=false;
try{
ResultSet rs=operate(sql,null);
if (rs==null||!rs.next()) return found;
found=true;
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return found;
}
public boolean hasRecord(String sql,String[] pstatementParameters){
boolean found=false;
try{
ResultSet rs=operate(sql,pstatementParameters);
if (rs==null||!rs.next()) return found;
found=true;
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return found;
}
public void close(){
try{
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
}catch(Exception e){
e.printStackTrace();
}
}
private void setCurrentConnection() throws Exception{
try{
if (debug)
topcheerConnection.setConnection(Constants.DRIVER,Constants.URL,Constants.USER,Constants.PASSWORD);
else
topcheerConnection.setConnection();
} catch (SQLException e){
e.printStackTrace();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
throw e;
}
}
private void releaseResultSet(ResultSet rs) throws SQLException{
if (rs!=null) rs.close();
}
private ResultSet operate(String sql,String[] parameters)
throws ConnectFailedException,Exception{
ResultSet rs=null;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed())
setCurrentConnection();
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
topcheerPreparedStatement.setPreparedStatement(topcheerConnection,sql,TopcheerPreparedStatement.TYPE_FORWARD_ONLY,TopcheerPreparedStatement.CONCUR_READ_ONLY);
if (parameters!=null){
topcheerPreparedStatement.clearParameters();
topcheerPreparedStatement.setString(parameters);
}
rs=topcheerPreparedStatement.executeQuery();
} catch(SQLException e){
System.out.println(sql);
releaseResultSet(rs);
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
throw e;
} catch(Exception e){
releaseResultSet(rs);
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
throw e;
}
return rs;
}
public static void main(String[] args){
TopcheerDynamicQuery app=new TopcheerDynamicQuery();
String sql="select * from web_news";
String sql2="select * from web_news where wnnewsid>? and wnnewsid<?";
String sql3="select * from web_news where 1>2";
String para[]=new String[2];
para[0]="6";
para[1]="5";
ResultSet rs=app.doQuery(sql);
try{
if (rs!=null){
while (rs.next()){
System.out.println(rs.getString(1));
}
rs.close();
}
} catch(SQLException e){
e.printStackTrace();
}
ResultSet rs2=app.doQuery(sql2,para);
try{
if (rs2!=null){
while (rs2.next()){
System.out.println(rs2.getString(1));
}
rs2.close();
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println(app.doQueryOne(sql));
System.out.println(app.doQueryOne(sql2,para));
System.out.println(app.doQueryOne(sql3));
System.out.println(app.hasRecord(sql));
System.out.println(app.hasRecord(sql2,para));
System.out.println(app.hasRecord(sql3));
app.close();
}
}
=====================================================================
package com.tzsw.hjyweb.db;
import java.sql.SQLException;
import java.sql.BatchUpdateException;
import com.tzsw.hjyweb.exception.*;
import com.tzsw.hjyweb.pub.Constants;
public class TopcheerDynamicUpdate{
private boolean debug=false;
private TopcheerConnection topcheerConnection;
private TopcheerPreparedStatement topcheerPreparedStatement;
public TopcheerDynamicUpdate(){
try{
topcheerConnection=new TopcheerConnection();
topcheerPreparedStatement=new TopcheerPreparedStatement();
setCurrentConnection();
} catch(Exception e){
e.printStackTrace();
}
}
/*
public TopcheerDynamicUpdate(boolean debug){
this.debug=debug;
try{
topcheerConnection=new TopcheerConnection();
topcheerPreparedStatement=new TopcheerPreparedStatement();
setCurrentConnection();
} catch(Exception e){
e.printStackTrace();
}
}
*/
public int doUpdate(String sql)
throws Exception{
int updateCount=0;
try{
updateCount=operate(sql,null);
} catch (Exception e){
//System.out.println(e);
throw e;
}
return updateCount;
}
public int doUpdate(String sql,String[] pstatementParameters)
throws Exception{
int updateCount=0;
try{
updateCount=operate(sql,pstatementParameters);
} catch (Exception e){
//System.out.println(e);
throw e;
}
return updateCount;
}
//批更新
//parameters 二维数组 更新数 每条的参数数组
public int[] doBatchUpdate(String sql,String[][] parameters)
throws Exception{
int updateCount[]=null;
try{
updateCount=batchOperate(sql,parameters);
} catch (Exception e){
//System.out.println(e);
throw e;
}
return updateCount;
}
private void setCurrentConnection() throws Exception{
try{
if (debug)
topcheerConnection.setConnection(Constants.DRIVER,Constants.URL,Constants.USER,Constants.PASSWORD);
else
topcheerConnection.setConnection();
} catch (SQLException e){
e.printStackTrace();
topcheerConnection.releaseConnection();
throw e;
}
}
private int operate(String sql,String[] parameters)
throws Exception{
int updateCount=0;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed())
setCurrentConnection();
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
topcheerConnection.setAutoCommit(false);
topcheerPreparedStatement.setPreparedStatement(topcheerConnection,sql);
if (parameters!=null){
topcheerPreparedStatement.clearParameters();
topcheerPreparedStatement.setString(parameters);
}
updateCount=topcheerPreparedStatement.executeUpdate();
topcheerConnection.commit();
topcheerConnection.setAutoCommit(true);
} catch(SQLException e){
e.printStackTrace();
System.out.println("update error!/n"+sql);
topcheerConnection.rollback();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
throw e;
} catch(Exception e){
topcheerConnection.rollback();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
throw e;
}
return updateCount;
}
private int[] batchOperate(String sql,String[][] parameters)
throws Exception{
int[] updateCounts=null;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed())
setCurrentConnection();
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
topcheerConnection.setAutoCommit(false);
topcheerPreparedStatement.setPreparedStatement(topcheerConnection,sql);
topcheerPreparedStatement.clearBatch();
for (int i=0;i<parameters.length;i++){
topcheerPreparedStatement.setString(parameters[i]);
topcheerPreparedStatement.addBatch();
}
updateCounts=topcheerPreparedStatement.executeBatch();
topcheerConnection.commit();
topcheerConnection.setAutoCommit(true);
} catch(BatchUpdateException e){
System.out.println("update error!/n"+sql);
topcheerConnection.rollback();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
updateCounts = e.getUpdateCounts();
SQLException SQLe = e;
StringBuffer sb_warnings=new StringBuffer();
while (SQLe!=null){
sb_warnings.append("error is happen./n");
sb_warnings.append("Message is "+SQLe.getMessage()+"/n");
sb_warnings.append("SQLState is "+SQLe.getSQLState()+"/n");
sb_warnings.append("ErrorCode is "+SQLe.getErrorCode()+"/n");
sb_warnings.append("Continuing....");
SQLe=SQLe.getNextException();
}
System.out.println(sb_warnings.toString());
} catch(SQLException e){
System.out.println("update error!/n"+sql);
topcheerConnection.rollback();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
System.out.println(e);
} catch(Exception e){
topcheerConnection.rollback();
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
System.out.println(e);
}
return updateCounts;
}
public void close(){
try{
topcheerPreparedStatement.releasePreparedStatement();
topcheerConnection.releaseConnection();
}catch(Exception e){
e.printStackTrace();
}
}
public String printUpdateCount(int updateCount){
String message="update "+updateCount+" record(s)!";
return message;
}
//-2
public String printUpdateCount(int[] updateCount){
if (updateCount==null) return "";
StringBuffer sb_result=new StringBuffer();
sb_result.append("update records are:");
for (int i=0;i<updateCount.length;i++){
sb_result.append(" "+updateCount[i]+"");
}
return sb_result.toString();
}
public static void main(String[] args) {
TopcheerDynamicUpdate app=new TopcheerDynamicUpdate();
String sql="insert into web_news(wnnewsid,wnnewstitle) values('6','ss')";
String sql2="insert into web_news(wnnewsid,wnnewstitle) values(?,?)";
String para[]=new String[2];
para[0]="7";
para[1]="ddd";
String para2[][]=new String[3][2];
para2[0][0]="8";
para2[0][1]="safs";
para2[1][0]="9";
para2[1][1]="safs";
para2[2][0]="10";
para2[2][1]="safs";
try{
//int status=app.doUpdate(sql);
//System.out.println(app.printUpdateCount(status));
//int status2=app.doUpdate(sql2,para);
//System.out.println(app.printUpdateCount(status2));
int[] status3=app.doBatchUpdate(sql2,para2);
System.out.println(app.printUpdateCount(status3));
} catch (Exception e){
e.printStackTrace();
}
app.close();
}
}
=======================================================
package com.tzsw.hjyweb.db;
import javax.sql.PooledConnection;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
public class TopcheerPoolConnection{
final int TRANSACTION_NONE=Connection.TRANSACTION_NONE;
final int TRANSACTION_READ_COMMITTED=Connection.TRANSACTION_READ_COMMITTED;
final int TRANSACTION_READ_UNCOMMITTED=Connection.TRANSACTION_READ_UNCOMMITTED;
final int TRANSACTION_REPEATABLE_READ=Connection.TRANSACTION_REPEATABLE_READ;
final int TRANSACTION_SERIALIZABLE=Connection.TRANSACTION_SERIALIZABLE;
private PooledConnection poolconnection;
private Connection connection;
public TopcheerPoolConnection(){
}
public void setConnection() throws SQLException,Exception{
connection=poolconnection.getConnection();
}
public void setPoolConnection() throws Exception{
poolconnection=TopcheerConnectionPoolDataSource.getConnectionPoolDataSource().getPooledConnection();
}
public Connection getConnection(){
return connection;
}
public void setAutoCommit(boolean b) throws SQLException{
connection.setAutoCommit(b);
}
public void commit() throws SQLException{
connection.commit();
}
public void rollback() throws SQLException{
connection.rollback();
}
public void releaseConnection() throws SQLException{
if (connection!=null&&!connection.isClosed())
connection.close();
}
public void closConnection() throws SQLException{
if (poolconnection!=null) poolconnection.close();
}
public String getSQLWarning() throws SQLException{
SQLWarning sqlwarnings=connection.getWarnings();
StringBuffer sb_warnings=new StringBuffer();
while (sqlwarnings!=null){
sb_warnings.append("error happened./n");
sb_warnings.append(" Message is "+sqlwarnings.getMessage()+"/n");
sb_warnings.append(" SQLState is "+sqlwarnings.getSQLState()+"/n");
sb_warnings.append(" ErrorCode is "+sqlwarnings.getErrorCode()+"/n");
sb_warnings.append("Continuing....");
sqlwarnings=sqlwarnings.getNextWarning();
}
return sb_warnings.toString();
}
public void setTransactionIsolation(int level) throws SQLException{
DatabaseMetaData dbMetaData=connection.getMetaData();
if (dbMetaData.supportsTransactionIsolationLevel(level))
connection.setTransactionIsolation(level);
}
}
========================================================
package com.tzsw.hjyweb.db;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
public class TopcheerPreparedStatement{
final static int CONCUR_READ_ONLY=ResultSet.CONCUR_READ_ONLY;
final static int CONCUR_UPDATABLE=ResultSet.CONCUR_UPDATABLE;
final static int FETCH_FORWARD=ResultSet.FETCH_FORWARD;
final static int FETCH_REVERSE=ResultSet.FETCH_REVERSE;
final static int FETCH_UNKNOWN=ResultSet.FETCH_UNKNOWN;
final static int TYPE_FORWARD_ONLY=ResultSet.TYPE_FORWARD_ONLY;
final static int TYPE_SCROLL_INSENSITIVE=ResultSet.TYPE_SCROLL_INSENSITIVE;
final static int TYPE_SCROLL_SENSITIVE=ResultSet.TYPE_SCROLL_SENSITIVE;
private PreparedStatement pstatement;
public TopcheerPreparedStatement() throws SQLException{
}
public void setPreparedStatement(TopcheerConnection topcheerConnection,String sql) throws SQLException{
pstatement=topcheerConnection.getConnection().prepareStatement(sql);
}
public void setPreparedStatement(TopcheerConnection topcheerConnection,String sql,int resultSetType,int resultSetConcurrency)
throws SQLException{
pstatement=topcheerConnection.getConnection().prepareStatement(sql,resultSetType,resultSetConcurrency);
}
public PreparedStatement getPreparedStatement() throws SQLException{
return pstatement;
}
public void setString(String[] pstatementParameters) throws SQLException{
for (int i=0;i<pstatementParameters.length;i++)
pstatement.setString(i+1,pstatementParameters[i]);
}
public void clearBatch() throws SQLException{
pstatement.clearBatch();
}
public void clearParameters() throws SQLException{
pstatement.clearParameters();
}
public void addBatch() throws SQLException{
pstatement.addBatch();
}
public boolean execute() throws SQLException{
return pstatement.execute();
}
public boolean execute(String sql) throws SQLException{
return pstatement.execute(sql);
}
public int[] executeBatch() throws BatchUpdateException,SQLException{
return pstatement.executeBatch();
}
public ResultSet executeQuery() throws SQLException{
return pstatement.executeQuery();
}
public ResultSet executeQuery(String sql) throws SQLException{
return pstatement.executeQuery(sql);
}
public int executeUpdate() throws SQLException{
return pstatement.executeUpdate();
}
public int executeUpdate(String sql) throws SQLException{
return pstatement.executeUpdate(sql);
}
public void releasePreparedStatement() throws SQLException{
if (pstatement!=null) pstatement.close();
}
}
===================================================================
package com.tzsw.hjyweb.db;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.tzsw.hjyweb.exception.*;
import com.tzsw.hjyweb.pub.Constants;
public class TopcheerQuery{
private boolean debug=false;
private TopcheerConnection topcheerConnection;
private TopcheerStatement topcheerStatement;
public TopcheerQuery(){
try{
topcheerConnection=new TopcheerConnection();
topcheerStatement=new TopcheerStatement();
setCurrentConnection();
setCurrentStatement();
} catch(Exception e){
e.printStackTrace();
}
}
public ResultSet doQuery(String sql){
ResultSet rs=null;
try{
rs=operate(sql);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return rs;
}
public String doQueryOne(String sql){
String result="";
try{
ResultSet rs=operate(sql);
if (rs==null||!rs.next()) return result;
result=rs.getString(1);
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return result;
}
public boolean hasRecord(String sql){
boolean found=false;
try{
ResultSet rs=operate(sql);
if (rs==null||!rs.next()) return found;
found=true;
} catch(ConnectFailedException e){
System.out.println(e);
} catch(Exception e){
System.out.println(e);
}
return found;
}
public void close(){
try{
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
}catch(Exception e){
e.printStackTrace();
}
}
private void setCurrentConnection() throws Exception{
try{
if (debug)
topcheerConnection.setConnection(Constants.DRIVER,Constants.URL,Constants.USER,Constants.PASSWORD);
else
topcheerConnection.setConnection();
topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
} catch (SQLException e){
e.printStackTrace();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
throw e;
}
}
private void setCurrentStatement() throws Exception{
topcheerStatement.setStatement(topcheerConnection,TopcheerStatement.TYPE_FORWARD_ONLY,TopcheerStatement.CONCUR_READ_ONLY);
}
private void releaseResultSet(ResultSet rs) throws SQLException{
if (rs!=null) rs.close();
}
private ResultSet operate(String sql)
throws ConnectFailedException,Exception{
ResultSet rs=null;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed()){
setCurrentConnection();
setCurrentStatement();
}
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
//topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
//topcheerStatement.setStatement(topcheerConnection,topcheerStatement.TYPE_FORWARD_ONLY,topcheerStatement.CONCUR_READ_ONLY);
rs=topcheerStatement.executeQuery(sql);
} catch(SQLException e){
System.out.println(sql);
e.printStackTrace();
releaseResultSet(rs);
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
throw e;
} catch(Exception e){
releaseResultSet(rs);
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
throw e;
}
return rs;
}
public static void main(String[] args){
TopcheerQuery app=new TopcheerQuery();
String sql="select * from web_news";
String sql2="select * from web_news where 1>2";
ResultSet rs=app.doQuery(sql);
try{
if (rs!=null){
while (rs.next()){
System.out.println(rs.getString(1));
}
}
rs.close();
} catch(SQLException e){
e.printStackTrace();
}
System.out.println(app.doQueryOne(sql));
System.out.println(app.doQueryOne(sql2));
System.out.println(app.hasRecord(sql));
System.out.println(app.hasRecord(sql2));
app.close();
}
}
=============================================================
package com.tzsw.hjyweb.db;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
public class TopcheerStatement{
final static int CONCUR_READ_ONLY=ResultSet.CONCUR_READ_ONLY;
final static int CONCUR_UPDATABLE=ResultSet.CONCUR_UPDATABLE;
final static int FETCH_FORWARD=ResultSet.FETCH_FORWARD;
final static int FETCH_REVERSE=ResultSet.FETCH_REVERSE;
final static int FETCH_UNKNOWN=ResultSet.FETCH_UNKNOWN;
final static int TYPE_FORWARD_ONLY=ResultSet.TYPE_FORWARD_ONLY;
final static int TYPE_SCROLL_INSENSITIVE=ResultSet.TYPE_SCROLL_INSENSITIVE;
final static int TYPE_SCROLL_SENSITIVE=ResultSet.TYPE_SCROLL_SENSITIVE;
private Statement statement;
public TopcheerStatement() throws SQLException{
}
public void setStatement(TopcheerConnection topcheerConnection) throws SQLException{
statement=topcheerConnection.getConnection().createStatement();
}
public void setStatement(TopcheerConnection topcheerConnection,int resultSetType,int resultSetConcurrency)
throws SQLException{
statement=topcheerConnection.getConnection().createStatement(resultSetType,resultSetConcurrency);
}
public Statement getStatement() throws SQLException{
return statement;
}
public void addBatch(String sql) throws SQLException{
statement.addBatch(sql);
}
public void clearBatch() throws SQLException{
statement.clearBatch();
}
public boolean execute(String sql) throws SQLException{
return statement.execute(sql);
}
public int[] executeBatch() throws BatchUpdateException,SQLException{
return statement.executeBatch();
}
public ResultSet executeQuery(String sql) throws SQLException{
return statement.executeQuery(sql);
}
public int executeUpdate(String sql) throws SQLException{
return statement.executeUpdate(sql);
}
public void releaseStatement() throws SQLException{
if (statement!=null) statement.close();
}
}
===============================================================
package com.tzsw.hjyweb.db;
import java.sql.SQLException;
import java.sql.BatchUpdateException;
import com.tzsw.hjyweb.exception.*;
import com.tzsw.hjyweb.pub.Constants;
public class TopcheerUpdate{
private boolean debug=false;
private TopcheerConnection topcheerConnection;
private TopcheerStatement topcheerStatement;
public TopcheerUpdate(){
try{
topcheerConnection=new TopcheerConnection();
topcheerStatement=new TopcheerStatement();
setCurrentConnection();
setCurrentStatement();
} catch(Exception e){
e.printStackTrace();
}
}
/*
public TopcheerUpdate(boolean debug){
this.debug=debug;
try{
topcheerConnection=new TopcheerConnection();
topcheerStatement=new TopcheerStatement();
setCurrentConnection();
} catch(Exception e){
e.printStackTrace();
}
}
*/
public int doUpdate(String sql)
throws Exception{
int updateCount=0;
try{
updateCount=operate(sql);
} catch (Exception e){
System.out.println(e);
}
return updateCount;
}
//批更新
public int[] doBatchUpdate(String[] sqls)
throws Exception{
int updateCount[]=null;
try{
updateCount=batchOperate(sqls);
} catch (Exception e){
System.out.println(e);
}
return updateCount;
}
private void setCurrentConnection() throws Exception{
try{
if (debug)
topcheerConnection.setConnection(Constants.DRIVER,Constants.URL,Constants.USER,Constants.PASSWORD);
else
topcheerConnection.setConnection();
topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
} catch (SQLException e){
e.printStackTrace();
topcheerConnection.releaseConnection();
throw e;
}
}
private void setCurrentStatement() throws Exception{
topcheerStatement.setStatement(topcheerConnection);
}
private int operate(String sql)
throws Exception{
int updateCount=0;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed()){
setCurrentConnection();
setCurrentStatement();
}
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
//topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
topcheerConnection.setAutoCommit(false);
//topcheerStatement.setStatement(topcheerConnection);
updateCount=topcheerStatement.executeUpdate(sql);
topcheerConnection.commit();
topcheerConnection.setAutoCommit(true);
} catch(SQLException e){
System.out.println("update error!/n"+sql);
topcheerConnection.rollback();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
throw e;
} catch(Exception e){
topcheerConnection.rollback();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
throw e;
}
return updateCount;
}
private int[] batchOperate(String[] sqls)
throws Exception{
int[] updateCounts=null;
try{
if (topcheerConnection.getConnection()==null){
throw new ConnectFailedException();
}
if (topcheerConnection.getConnection().isClosed()) {
setCurrentConnection();
setCurrentStatement();
}
if (topcheerConnection.getSQLWarning().length()>0)
System.out.println(topcheerConnection.getSQLWarning());
//topcheerConnection.setTransactionIsolation(topcheerConnection.TRANSACTION_READ_COMMITTED);
topcheerConnection.setAutoCommit(false);
//topcheerStatement.setStatement(topcheerConnection);
topcheerStatement.clearBatch();
for (int i=0;i<sqls.length;i++){
topcheerStatement.addBatch(sqls[i]);
}
updateCounts=topcheerStatement.executeBatch();
topcheerConnection.commit();
topcheerConnection.setAutoCommit(true);
} catch(BatchUpdateException e){
System.out.println("update error!/n");
topcheerConnection.rollback();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
updateCounts = e.getUpdateCounts();
SQLException SQLe = e;
StringBuffer sb_warnings=new StringBuffer();
while (SQLe!=null){
sb_warnings.append("error is happen./n");
sb_warnings.append("Message is "+SQLe.getMessage()+"/n");
sb_warnings.append("SQLState is "+SQLe.getSQLState()+"/n");
sb_warnings.append("ErrorCode is "+SQLe.getErrorCode()+"/n");
sb_warnings.append("Continuing....");
SQLe=SQLe.getNextException();
}
System.out.println(sb_warnings.toString());
} catch(SQLException e){
System.out.println("update error!/n");
topcheerConnection.rollback();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
System.out.println(e);
} catch(Exception e){
topcheerConnection.rollback();
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
System.out.println(e);
}
return updateCounts;
}
public void close(){
try{
topcheerStatement.releaseStatement();
topcheerConnection.releaseConnection();
}catch(Exception e){
e.printStackTrace();
}
}
public String printUpdateCount(int updateCount){
String message="update "+updateCount+" record(s)!";
return message;
}
public String printUpdateCount(int[] updateCount){
if (updateCount==null) return "";
StringBuffer sb_result=new StringBuffer();
sb_result.append("update records are:");
for (int i=0;i<updateCount.length;i++){
sb_result.append(" "+updateCount[i]+"");
}
return sb_result.toString();
}
public static void main(String[] args) {
TopcheerUpdate app=new TopcheerUpdate();
String sql="update web_news set wnnewstitle='aaaa' where wnnewstitle='safs'";
String sql2="delete from web_news where wnnewstitle='aaaa' and wnnewsid>8";
String[] para=new String[2];
para[0]=sql;
para[1]=sql2;
try{
int status=app.doUpdate(sql);
System.out.println(app.printUpdateCount(status));
int[] status3=app.doBatchUpdate(para);
System.out.println(app.printUpdateCount(status3));
} catch (Exception e){
e.printStackTrace();
}
app.close();
}
}
- 一个导库的类DataMove
- php画图的一个类库
- 写一个跟踪的类库
- 操作 sqlite封装的一个类库
- 一个简易的反射类库NMSReflector
- 基于paramiko的一个类库
- 一个简易的反射类库NMSReflector
- 一个注册表的类
- 一个实用的类
- 一个完整的类
- 一个分页的类
- 一个天气预报的类
- 一个类的产生
- java的一个类!
- 一个类的生命周期
- Net 图片上传的一个类库的源码
- .Net 图片上传的一个类库的源码
- asp.Net_图片上传的一个类库的源码
- 第八套广播体操 和 眼保健操
- Linux能否守住HPC市场?
- Linux启动全线提速法
- .net编程中的一些技巧(一)
- 仅通过崩溃地址找出源代码的出错行
- 一个导库的类DataMove
- 先做Jpeg读取的部分~~
- Loading JPEGs to DirectDraw Surfaces
- JFace备忘
- 文件上传
- 修炼一名程序员的职业水准(林庆忠__署名原创)
- 何时使用聚集索引或非聚集索引&海量分页?
- Jdom使用例子
- 为了房子而奋斗!