Java DB select 特定行的特定列

Java DB select specific column on specific row

第一个 post 在这里 :) 疯狂寻求帮助。

我想要做的是检索在我的数据库中存储为 blob 的特定图像。我不明白为什么这个查询没有执行,我一到达 executeQuery 语句就得到一个异常。

我的table是:

名称 x 坐标 y 坐标远景 第一屏 0 0 图片 secondscreen 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);

我猜这与您构建查询的方式有关。尝试改用准备好的语句。

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