日期:2014-05-20 浏览次数:20857 次
private static BasicDataSource dataSource;
public void setDataSource(BasicDataSource dataSource){
this.dataSource=dataSource;
}
Log log;
public void setLog(Log log) {
this.log = log;
}
int i = 1;
private static final String SAVESQL = "insert into mcevent_c (LINEMCID,EVENTDATE,EVENTCODE,MAIN_MSG,SUB_MSG,SEQ) values(?,to_date(?,'yyyy/mm/dd HH24:mi:ss'),?,?,?,?)";
@Override
public synchronized void save(McEvent mc) throws Exception {
Connection con = null;
PreparedStatement ps = null;
int set=0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
try {
con = dataSource.getConnection();
ps = con.prepareStatement(SAVESQL);
ps.setString(1, mc.getLineMCID());
ps.setString(2, sdf.format(mc.getEventDate().getTime()));
ps.setString(3, mc.getEventCode());
ps.setString(4, mc.getMainMSG());
ps.setString(5, mc.getSubMSG());
ps.setInt(6, mc.getSeq());
set=ps.executeUpdate();
con.commit();
System.out.println("set="+set+" "+ mc.getLineMCID() + " "
+ sdf.format(mc.getEventDate().getTime()) + " "
+ mc.getEventCode() + " " + mc.getMainMSG() + " ____"
+ mc.getSubMSG() + "_______ " + mc.getSeq());
} catch (SQLException e2) {
con.rollback();
e2.printStackTrace();
log.logger.error(e2.getMessage());
throw e2;
} catch (Exception e2) {
con.rollback();
e2.printStackTrace();
log.logger.error(e2.getMessage());
throw e2;
} finally {
try {
DBUtil.closeConnection(con, ps);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@172.30.60.58:1538:SPCGTHR"/>
<property name="username" value="spc"/>
<property name="password" value="spc"/>
</bean>
客户端程序
public void start() {
try {
serverSocket = new ServerSocket(8880);