第一篇文章在这里:)疯狂地寻求帮助。
我要做的是检索在我的数据库中存储为blob的特定图像。我无法弄清楚为什么这个查询没有执行,我一到达executeQuery语句就会收到异常。
我的表是:
命名xcoordinate ycoordinate vista firstscree 0 0 imag 秒屏0 1 img2 ......等等。
ResultSet rs = null;
Statement stmnt = null;
Connection con = null;
String host = ...
String unm = ...
String pswrd = ...
BufferedImage imgt = null;
InputStream fis = null;
int xcoord;
int ycoord;
int newcoord;
String SQLNorth = "select vista from location where xcoordinate = "+xcoord+" and ycoordinate = "+newcoord;
newcoord = ycoord + 1;
System.out.println("New coord x and y are" + xcoord + newcoord);
con = DriverManager.getConnection(host, unm, pswrd);
stmnt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmnt.executeQuery(SQLNorth);
rs.next();
fis = rs.getBinaryStream(1);
imgt = javax.imageio.ImageIO.read(fis);
Image newImg = SwingFXUtils.toFXImage(imgt, null);
img_1.setImage(newImg);
答案 0 :(得分:0)
我的猜测是,它与您构建查询的方式有关。请尝试使用预备语句。
ResultSet rs = null;
PreparedStatement stmnt = null;
Connection con = null;
String host = ...
String unm = ...
String pswrd = ...
BufferedImage imgt = null;
InputStream fis = null;
int xcoord;
int ycoord;
int newcoord;
String SQLNorth = "select vista from location where xcoordinate = ? and ycoordinate = ?";
newcoord = ycoord + 1;
System.out.println("New coord x and y are" + xcoord + newcoord);
con = DriverManager.getConnection(host, unm, pswrd);
stmnt = con.prepareStatement(SQLNorth);
stmnt.setInt(1, xcoord);
stmnt.setInt(2, newcoord);
rs = stmnt.executeQuery(SQLNorth);
rs.next();
fis = rs.getBinaryStream(1);
imgt = javax.imageio.ImageIO.read(fis);
Image newImg = SwingFXUtils.toFXImage(imgt, null);
img_1.setImage(newImg);