0

我在以下代码中遇到异常

PreparedStatement pstmt;
Connection conn = DriverManager.getConnection(
   "jdbc:jtds:sqlserver://Irfan:1433/Pictures", "sa", "ent@");      

java.sql.Blob bl=GetBolbDataFromDB();
InputStream fs = bl.getBinaryStream();
len = bl.length() ;

query = ("insert into NewPics2 VALUES(?,?,?,?)");
pstmt = conn.prepareStatement(query);
pstmt.setString(1, model);
pstmt.setString(2, catid);
pstmt.setString(3, ornid);
**pstmt.setBinaryStream(4, fs);**

完整的堆栈跟踪如下

Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at jewelleryerpapplication.GUI.Orders.CheckPrice.GetPicInfo(CheckPrice.java:1157)
at jewelleryerpapplication.GUI.Orders.CheckPrice.txtModelNoKeyPressed(CheckPrice.java:2300)
at jewelleryerpapplication.GUI.Orders.CheckPrice.access$1500(CheckPrice.java:37)
at jewelleryerpapplication.GUI.Orders.CheckPrice$18.keyPressed(CheckPrice.java:702)
at java.awt.Component.processKeyEvent(Component.java:6463)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2829)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1908)
4

3 回答 3

1

简单地说,您的 jdbc 驱动程序没有实现最新版本的 jdbc:它没有方法 setBinaryStream()。这意味着你不能使用它。您可以尝试 setBlob() 与完全读取的图像。

于 2013-02-21T11:22:05.610 回答
1

从堆栈跟踪来看,您调用的方法似乎是抽象的。根据文档, JtdsPreparedStatement.setBinaryStream()采用三个参数:索引、流和长度。

尝试添加一个int作为长度参数:pstmt.setBinaryStream(4, fs);

于 2013-02-21T11:24:44.877 回答
0

尝试转换

java.sql.Blob bl=GetBlobDataFromDB();
String fs = bl.getBytes();
于 2013-02-21T11:25:07.517 回答