假设我有这样的代码:
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.*;
public class InsertImg2Dbase extends JFrame implements ActionListener{
JButton open = new JButton("Open image to save...");
private Connection con;
public void getConnection(){
try{
if(con==null){
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
con=DriverManager.getConnection("jdbc:db2://localhost:50001/sample","username","password");
}
}catch (SQLException e){
JOptionPane.showMessageDialog(null, e.getMessage());
}catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
if(source==open){
// this is where the event when opening the file to be saved will be coded
}
}
public InsertImg2Dbase(){
ActionListener al = new InsertImg2Dbase();
open.setBounds(20, 20, 175, 25);
open.addActionListener(al);
add(open);
}
public void properties(){
setLayout(null);
setTitle("Open Image To Save");
setResizable(false);
setSize(220,90);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args){
InsertImg2Dbase ins = new InsertImg2Dbase();
ins.properties();
}
}
我应该在代码中添加什么,以便 JButton 将打开一个资源管理器以打开一个图像文件(例如 jpeg、png、gif、bmp),该文件将作为 blob 保存到我的数据库(比如我的表名是:“images”)文件。我可以添加一个函数来调整我的图像大小,比如说在保存到我的数据库之前的尺寸为 300x650?
我欢迎任何帮助,我仍在学习过程中,如果您能指导我,我将不胜感激。欢迎任何帮助!谢谢