我一直试图从我的表image中检索所有图像,第二列的image.The代码看起来很好,但是它产生了一个错误invalid column index.Please帮助。
package p1;
import java.sql.*;
import java.io.*;
public class test
{
public static void main(String[] args)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","admin");
PreparedStatement ps=con.prepareStatement("select image from imagetable");
ResultSet rs=ps.executeQuery();
int i=0;
while(rs.next())
{
Blob b=rs.getBlob(2);
byte barr[]=b.getBytes(1,(int)b.length());
FileOutputStream fout=new FileOutputStream("d:\\img"+i+".png"); i++;
fout.write(barr);
fout.close();
}//end of while
System.out.println("ok");
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
} 发布于 2016-12-17 20:13:02
试一试
Blob b=rs.getBlob("image"); 而不是
Blob b=rs.getBlob(2);异常的原因是您正在检索单个值,这就是列索引无效的原因。
https://stackoverflow.com/questions/41202537
复制相似问题