private void insertData(final String driver, final String url,
final String userName, final String password, int psize,
String fileName, HashMap<String, String> map,HttpServletResponse response) throws IOException {
PrintWriter out=response.getWriter();
try {
try {
Class.forName(driver).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
}
Connection conn = DriverManager.getConnection(url, userName,
password);
String sql = "insert into frame_res_photo(resuri,restype, filename,photo,psize,phototype,photoext,sortno,description,creatorid,createdate) values(?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, map.get("resuri"));
pstmt.setString(2, "FRT001");
pstmt.setString(3, fileName);
pstmt.setString(4, map.get("photo"));
pstmt.setBigDecimal(5, new BigDecimal(psize));
pstmt.setString(6, "FPT004");
pstmt.setString(7, "png");
pstmt.setBigDecimal(8, new BigDecimal(0));
pstmt.setString(9, map.get("description"));
pstmt.setString(10, "阮国辉");
/**java.util.Date与java.sql.Date的相互转换**/
java.util.Date now = new java.util.Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date sd = Date.valueOf(df.format(now));
/**************************************/
pstmt.setDate(11, sd);
int num = pstmt.executeUpdate();
out.println(num);
} catch (SQLException e) {
// TODO: handle exception
out.println(e.getMessage());
}
}