public static void insertDemo(String[] args) throws Exception {
MsgSwapDAOImpl dao = new MsgSwapDAOImpl()
Connection conn = dao.jdbcUtil.getConnection()
String appKey ="40825Td288461463"
String msg = "wlllllll"
conn.setAutoCommit(false)
String sql = "insert into TTT(ID, CREATE_DATE) values(?,?)"
PreparedStatement pstmt = conn.prepareStatement(sql)
pstmt.setInt(1, 888888)
pstmt.setTimestamp(2, TimeUtil.nowTimestamp())
pstmt.executeUpdate()
conn.commit()
conn.close()
}
public static Date dateTimeString2Date(String date_str) {try {
Calendar cal = Calendar.getInstance()
java.sql.Timestamp timestampnow = new java.sql.Timestamp(cal.getTimeInMillis())
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
ParsePosition pos = new ParsePosition(0)
java.util.Date current = formatter.parse(date_str, pos)
timestampnow = new java.sql.Timestamp(current.getTime())
return timestampnow
}
catch (NullPointerException e) {
return null
}
}
//格式以上面不一样yyyy-MM-dd
public static Date dateString2Date(String date_str) {
try {
Calendar cal = Calendar.getInstance()
java.sql.Timestamp timestampnow = new java.sql.Timestamp(cal.getTimeInMillis())
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd")
ParsePosition pos = new ParsePosition(0)
java.util.Date current = formatter.parse(date_str, pos)
return current
}
catch (NullPointerException e) {
return null
}
}
插入数据库,用java.sql.PreparedStatement即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)