khstar
java와 오라클 간의 Date Format 맞추기 본문
public int UserDataInsert(UserData ds) throws SQLException{
Connection con = connectDB();
PreparedStatement ps = null;
int result = 0;
Calendar cl = Calendar.getInstance();
cl.setTime(ds.getVocStartdate());
try{
ps = con.prepareStatement("INSERT INTO VOCMASTER (PROCID,CUSTNAME,CUSTEMAIL,CUSTMOBILE,CUSTAGE,CUSTGENDER," +
"VOCSTARTDATE,VOCTITLE,VOCTYPE,VOCCONTENT) " +
"values (?,?,?,?,?,?,TO_DATE(?,'YYYYMMDDHHMISS'),?,?,?)") ;
long ut = cl.getTimeInMillis();
DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
String ll = df.format(ut);
System.out.println(ll);
ps.setString(1, ds.getProcId());
ps.setString(2, ds.getCustName());
ps.setString(3, ds.getCustEmail());
ps.setString(4, ds.getCustMobile());
ps.setString(5, ds.getCustAge());
ps.setString(6, ds.getCustGender());
ps.setString(7, ll);
ps.setString(8, ds.getVocTitle());
ps.setString(9, ds.getVocType());
ps.setString(10, ds.getVocContent());
result = ps.executeUpdate();
ps.close() ;
con.close() ;
}catch(Exception e){
System.out.println("Cannot execute query: " + e.getMessage());
}
return result;
}
}
바쁜 관계로 주석은 다음에 남기겠습니다.. ㅡㅡ;;;