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

时间:2016-10-07 19:44:34

标签: java mysql

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

 }

这是行动执行部分:

  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());

1 个答案:

答案 0 :(得分:0)

似乎已经针对Blob对象的对象执行了 toString() - 应该已经取代了内容。