Connection cn;
Statement st;
PreparedStatement pstmt=null;
PreparedStatement pst;
ResultSet rs;
Object fname, mname, lname, bdate, nation, statusq,InstNo, photo, combo, place, mimi;
int status;
private void btnNextMouseClicked(java.awt.event.MouseEvent evt) {
fname=txtFirtsName.getText();
lname=txtLastName.getText();
mname=txtMiddleName.getText();
InstNo=txtInstituteNo.getText();
place=txtPlacBirth.getText();
//photo=txtPicturePath.getText();
status=combostatus.getSelectedIndex();
Object dave=((JTextField)chooserBirthDate.getDateEditor().getUiComponent()).getText();
Object isa=combonation.getSelectedItem();
Object photo=pictureName.getClass();
// pst.setBytes();
// bdate=((JTextField)chooserBirthDate.getDateEditor().getUiComponent()).getText();
if(status==1){
statusq=("In Active");
}
else{
statusq="Active";}
try{
String addrecords="insert into brothers(FirstName, MiddleName, LastName, BirthDate, BirthPlace, Nationality, InstituteNumber, Status, Picture) values('"+
fname +"', '" +
mname +"', '" +
lname +"', '" +
dave +"', '" +
place +"', '" +
isa +"', '" +
InstNo +"', '" +
statusq +"', '" +
photo +"')";
//wrapField();
st.executeUpdate(addrecords);
}
私のファイル選択コードとバイナリへの画像の変換:
private void btnFileChooserActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser izoChooser=new JFileChooser();
izoChooser.showOpenDialog(null);
File pictureBrother=izoChooser.getSelectedFile();
pictureName=pictureBrother.getAbsolutePath();
txtPicturePath.setText(pictureName);
try {
File image=new File(pictureName);
FileInputStream fis=new FileInputStream(image);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] buf=new byte[1024];
for(int readNum; (readNum=fis.read(buf))!=-1;){
bos.write(buf,0,readNum);
}
person_image=bos.toByteArray();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
//e.printStackTrace();
}
コードの最後でこれらの変数を宣言しました。
private javax.swing.JTextField txtTrial;
// End of variables declaration
String pictureName=null;
int s=0;
byte[] person_image=null;
}
質問: 私のコードはエラーをスローしませんが、データベースでは、選択した画像に関係なく、画像の BLOB 列に 8B しか登録されません。ただし、データベースに移動してからアップロードすることにより、データベースから画像を直接アップロードすると、画像がデータベースにアップロードされます。何が問題になる可能性がありますか?
私の主な問題はここにあります:オブジェクト photo=pictureName.getClass(); だと思います。
プリペアド ステートメントを使用する場合、次のようになります。
しかし、.getBytes(); はありません。