我正在尝试使用java mysql.setIcon(imageIcon)从数据库查看图像后设置图像大小。此标签以供查看。 到目前为止,我尝试过的工作都附在下面。
String id = txtid.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/empay","root","");
pst = con.prepareStatement("select * from records where id=?");
pst.setString(1, id);
rs = pst.executeQuery();
if(rs.next()==false)
{
JOptionPane.showMessageDialog(this,"Data not Found");
}
else
{
String firstname = rs.getString("firstname");
String lastname = rs.getString("lastname");
String address = rs.getString("address");
String bsal = rs.getString("bsal");
Blob blob1 =rs.getBlob("photo");
byte[ ] _imagebytes=blob1.getBytes( 1, (int) blob1.length( ) );
txtfirstname.setText(firstname.trim());
txtlastname.setText(lastname.trim());
txtaddress.setText(address.trim());
txtbsal.setText(bsal.trim());
imagelabel.setIcon(_imagebytes);