62,634
社区成员




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);
} catch (IOException e) {
e.printStackTrace();
}
while (true) {
try {
Socket s = serverSocket.accept();
invoke(s);
} catch (IOException e) {
e.printStackTrace();
log.logger.error(e);
}
}
}
public void invoke(final Socket socket) {
new Thread(new Runnable() {
@SuppressWarnings("unchecked")
public void run() {
ObjectInputStream is = null;
String PTName = null;
List<McEvent> mcList = null;
try {
is = new ObjectInputStream(new BufferedInputStream(
socket.getInputStream()));
PTName = socket//获得PT服务器IP最后两位作为标
.getInetAddress()//志位 区分是哪台服务器
.getHostAddress()//传来的信息无法插入数据库
.substring(
socket.getInetAddress().getHostAddress()
.lastIndexOf(".") + 1);
Object obj = is.readObject();
if (obj != null) {
mcList = (List<McEvent>) obj;
mcEventJDBCServiceImpl.saveAll(mcList);
}
} catch (IOException ex) {
ex.printStackTrace();
log.logger.error(ex.getMessage());
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
log.logger.error(ex.getMessage());
} catch (Exception e) {
e.printStackTrace();
log.logger.error(e.getMessage());
try {
ExceptionUtil.saveEvent(mcList, PTName);
} catch (Exception e1) {
e1.printStackTrace();
log.logger.error(e1.getMessage());
}
} finally {
try {
is.close();
} catch (Exception ex) {
}
try {
socket.close();
} catch (Exception ex) {
}
}
}
}).start();
}
}