这里有史以来的第一篇文章:)疯狂地寻求帮助。
我想做的是检索数据库中存储为blob的特定图像。我不明白为什么这个查询没有执行,我一到达executeQuery语句就得到一个异常。
我的桌子是:
名称x坐标y坐标视景第一层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);
我的猜测是,这与构建查询的方式有关。请尝试使用准备好的语句。
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);