我坚持尝试使用我的 Java 代码上传图像。我正在使用数据访问对象并拥有 ojdbc5 和 ordim 库。我遇到的主要问题是尝试使用以下代码行插入图像: stmtInsert.setImage(8, ORDSYS.ORDImage.init());
我多年来一直被困在这一点上。
public void createImageInfo(
final String user_ID,
final int photo_ID,
final int num_views,
final double price,
final String photo_Name,
final String imageCategory,
final Calendar dateUploaded,
final ORDSYS.ORDImage.init(image))
{
PhotoSysDAO result = null;
PreparedStatement stmtInsert = null;
Connection conn = null;
try
{
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle server",
"username", "password");
//open a connection to db...needs your account and password
//int ratingID = RatingsDAO.getUniqueRatingId(conn);
StringBuilder sbInsert = new StringBuilder();
sbInsert.append("INSERT INTO ");
sbInsert.append("Photos");
sbInsert.append(" VALUES (");
sbInsert.append("SequenceSet.seq_photo_id.nextval, ?, ?, ?, ?, ?, ?, ?, ?)");
Calendar date = Calendar.getInstance();
stmtInsert.setInt(1, photo_ID);
stmtInsert.setString(2, user_ID);
stmtInsert.setInt(3, num_views);
stmtInsert.setDouble(4, price);
stmtInsert.setString(5, photo_Name);
stmtInsert.setString(6, imageCategory);
stmtInsert.setString(7, new SimpleDateFormat("dd/MMM/yyyy").format(date));
//stmtInsert.setImage(8, photo.ORDSYS.ORDIMGB);
stmtInsert.setImage(8, ORDSYS.ORDImage.init());
int rows = stmtInsert.executeUpdate();
if (rows != 1)
{
throw new SQLException("executeUpdate return value: " + rows);
}
}
catch (SQLException ex)
{
System.out.println("There was an error in connecting to the database");
}
finally
{
PhotoSysDAO.closeStatement(stmtInsert);
PhotoSysDAO.closeJDBCConnection(conn);
}
//return result;
}