gpt4 book ai didi

java - "org.apache.derby.client.ClientBlob@518bb3a1"而不是显示在数据库中的 Jtable 上的图像

转载 作者:行者123 更新时间:2023-11-30 22:11:42 25 4
gpt4 key购买 nike

“org.apache.derby.client.ClientBlob@518bb3a1”显示在图像应该显示的 jtable 列中。我将 gif 图像作为 BLOB 存储到 java derby 数据库中。这是什么意思?

这是渲染器类:

 package JavaApplication29;
import java.awt.Component;
import javax.swing

import javax.swing.table.DefaultTableCellRenderer;

public class ImageRenderer extends DefaultTableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table,Object
value, boolean isSelected,boolean hasFocus, int row, int column)
{
JLabel label = new JLabel();

if (value!=null) {
label.setHorizontalAlignment(JLabel.CENTER);

label.setIcon(new ImageIcon((byte[])value));
}

return label;
}

}

这是 Action 执行部分:

  DefaultTableModel model = new DefaultTableModel();




String sqlQuery = "select COLUMN1, COLUMN2, COLUMN3, COLUMN4,
COLUMN5 from APP.DATA123 "
+ "where (COLUMN1 = ?) AND (COLUMN2 = ?) AND (COLUMN3 = ?) OR
(COLUMN2
= ?) AND (COLUMN3 = ?)";



String abc = jTextField2.getText();
String cba = (String)jComboBox1.getSelectedItem();
String cab = (String)jComboBox2.getSelectedItem();
String data = "jdbc:derby://localhost:1527/sample";
try (
Connection conn = DriverManager.getConnection(
data, "app", "app");
PreparedStatement st = conn.prepareStatement(sqlQuery)) {



Class.forName("org.apache.derby.jdbc.ClientDriver");
st.setString(1, abc);
st.setString(2, cba);
st.setString(3, cab);
st.setString(4, cba);
st.setString(5, cab);
ResultSet rec = st.executeQuery();
jTable1.getColumnModel().getColumn(6).setCellRenderer(new
ImageRenderer());
jTable1.setModel(DbUtils.resultSetToTableModel(rec));

st.close();


} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println("Error: " + e.toString()
+ e.getMessage());

最佳答案

toString() 似乎是针对 Blob 对象的对象执行的 - 应该取而代之的是内容。

关于java - "org.apache.derby.client.ClientBlob@518bb3a1"而不是显示在数据库中的 Jtable 上的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39924758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com