Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误java.sql.SQLException:从数据库检索Blob(图像)时,SQLite JDBC驱动程序未实现_Java_Database_Swing_Sqlite_Jdbc - Fatal编程技术网

错误java.sql.SQLException:从数据库检索Blob(图像)时,SQLite JDBC驱动程序未实现

错误java.sql.SQLException:从数据库检索Blob(图像)时,SQLite JDBC驱动程序未实现,java,database,swing,sqlite,jdbc,Java,Database,Swing,Sqlite,Jdbc,当我试图从Sqlite数据库检索图像(Blob)文件时,它会给我以下错误。我使用过很多JAR,比如rs2xml、sqlitejdbc-v056、sqlite-jdbc-3.8.11,甚至它的所有旧版本。 这是stacktrace java.sql.SQLException: not implemented by SQLite JDBC driver at org.sqlite.Unused.unused(Unused.java:31) at org.sqlite.Unused.getBlob(U

当我试图从Sqlite数据库检索图像(Blob)文件时,它会给我以下错误。我使用过很多JAR,比如rs2xml、sqlitejdbc-v056、sqlite-jdbc-3.8.11,甚至它的所有旧版本。 这是stacktrace

java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.Unused.unused(Unused.java:31)
at org.sqlite.Unused.getBlob(Unused.java:86)
at Show$2.actionPerformed(Show.java:75)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$300(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
这是我的密码

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class Show extends JFrame {

    private JPanel contentPane;
    private JTextField id;
    BufferedImage bufImg = null;
    JLabel img = null;
    InputStream in = null;
    ImageIcon imgs = null;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Show frame = new Show();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    Connection con = null;

    public Show() {
        con = dB.Connect();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 588, 432);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        id = new JTextField();
        id.setBounds(158, 23, 86, 20);
        contentPane.add(id);
        id.setColumns(10);

        JButton show = new JButton("New button");
        show.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    String q = "select image from showme where id='" + id.getText() + "'";
                    PreparedStatement ps = con.prepareStatement(q);
                    ResultSet rs = ps.executeQuery();
                    try {
                        while (rs.next()) {
                            // problems might be occurring in here
                            Blob blob = rs.getBlob(2);
                            ImageIcon icon = new ImageIcon(blob.getBytes(2, (int) blob.length()));
                            img.setIcon(icon);
                        }
                    } catch (SQLException x) {
                        x.printStackTrace();
                    }

                    JOptionPane.showMessageDialog(null, "Done");

                    // in.close();
                    rs.close();
                    ps.close();

                } catch (Exception c) {
                    c.printStackTrace();
                }
            }
        });
        show.setBounds(302, 22, 89, 23);
        contentPane.add(show);

        img = new JLabel("");
        img.setBounds(151, 99, 325, 284);
        contentPane.add(img);
    }
}
编辑: 我试着用Bytearray。虽然它没有给我任何错误,但它没有给我任何输出!这是修改后的部分

   try {
        String q = "select image from showme where id='"+id.getText()+"'";
        PreparedStatement ps = con.prepareStatement(q);
        ResultSet rs = ps.executeQuery();       
         if(rs.next()) {
            byte[] imgss = rs.getBytes("image");
            //Resize The ImageIcon
            ImageIcon mage = new ImageIcon(imgss);
            Image im = mage.getImage();
            Image myImg = im.getScaledInstance(imgss.length, imgss.length,imgss.length);
            ImageIcon newImage = new ImageIcon(myImg);
            img.setIcon(newImage);
            JOptionPane.showMessageDialog(null, "Done");
        }
    }
试试这个:

byte[] byteArr = rs.getBytes("image"); 
改用
getBinaryStream()
。如下所示:

ResultSet rs=ps.executeQuery();     
InputStream in = rs.getBinaryStream("image");
ByteArrayOutpuStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead = in.read(buffer);
while (bytesRead > -1)
{
  out.write(buffer, bytesRead)
  bytesRead = in.read(buffer);
}
byte[] picture = out.toByteArray();
in.close();
当然,您需要在上面添加异常处理

如果您使用的是Apache Commons IO库,则可以使用
IOUtils.toByteArray()


错误:

java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.Unused.unused(Unused.java:31)
at org.sqlite.Unused.getBlob(Unused.java:86)
//problems might be occurring in here 
Blob blob=rs.getBlob(2);
Byte blob=rs.getByte(2);
AT:

java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.Unused.unused(Unused.java:31)
at org.sqlite.Unused.getBlob(Unused.java:86)
//problems might be occurring in here 
Blob blob=rs.getBlob(2);
Byte blob=rs.getByte(2);
试试看:

java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.Unused.unused(Unused.java:31)
at org.sqlite.Unused.getBlob(Unused.java:86)
//problems might be occurring in here 
Blob blob=rs.getBlob(2);
Byte blob=rs.getByte(2);

如果不使用getBlob方法,如何检索Blob文件?您可以将图像作为字节数组resultset.getBytes(“图像”)获取;可能此链接可能有助于我使用bytearray。虽然它没有给我错误。但它并没有将图像设置为Jlabel!不知道为什么!问题是它没有在JLabel中向我显示图片。还有其他问题吗?@CodeHead:
newbytearrayoutputstream()非常好。是否验证字节数组是否包含正确的数据?因此,我们知道检索或显示图像时是否存在问题。我已验证数据库中的数据是否已损坏和正确。我不是指数据库中的数据,而是指检索数据(例如,使用调试器)后字节数组的内容。抱歉,问了一个蹩脚的问题。我很傻。你能告诉我怎样才能证实吗?