0

Javaコードで画像をアップロードしようとして立ち往生しています。私はデータ アクセス オブジェクトを使用しており、ojdbc5 および ordim ライブラリを使用しています。私が抱えている主な問題は、次のコード行を使用して画像を挿入しようとすることです。

私はこの時点で何年も立ち往生しています。

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;
}
4

1 に答える 1

-2

データベースに画像を保存しないことをお勧めします。データベースのストレージとパフォーマンスに悪影響を及ぼします。写真をフォルダの場所に保存し、パスをデータベースに保存します。

于 2012-12-11T18:07:37.613 に答える