尝试通过从一个类调用连接方法到另一个类来加载已创建的数据库。 这是调用连接到db
的方法的GUIClasspublic class GUIController implements Initializable {
public void loadImg() throws IOException, Exception {
try {
rs = dbc.Story();
Stage stage = new Stage();
rs.next();
fis = rs.getBinaryStream(1);
BufferedImage imgt = null;
try {
imgt = javax.imageio.ImageIO.read(fis);
} catch (IOException ex) {
System.out.println("Image failed to load.");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
我在这里连接到数据库
public class DBOperations {
private Connection connection;
private Statement statement;
private PreparedStatement stmnt;
public ResultSet Story() throws ClassNotFoundException {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
String query = "select vista from location where ycoordinate = ? and xcoordinate = ?";
connection = DriverManager.getConnection("jdbc:derby:" + System.getProperty("user.dir") + "/.." + "/NewGame");
stmnt = connection.prepareStatement(query);
int x = 0;
int y = 0;
stmnt.setInt(1, y);
stmnt.setInt(2, x);
rs = stmnt.executeQuery();
} catch (SQLException e) {
do {
System.out.println("SQLState:" + e.getSQLState());
System.out.println("Error Code:" + e.getErrorCode());
System.out.println("Message:" + e.getMessage());
Throwable t = e.getCause();
while (t != null) {
System.out.println("Cause:" + t);
t = t.getCause();
}
e = e.getNextException();
} while (e != null);
} catch (IOException ex) {
Logger.getLogger(DBOperations.class.getName()).log(Level.SEVERE, null, ex);
}
返回rs; }
我最后得到一个null。
Couldn't open the story C:\Users\Konstantin\Desktop\InteractiveFictionGamePC Imported\NewGame[Ljava.lang.StackTraceElement;@500d4560
null
我认为这可能与我在尝试访问它之前创建NewGame文件夹有关。我有一个现成的数据库,我正在复制,然后运行副本中的所有内容。难道这就是我无法打开数据库的原因吗?我正在运行Java SE 8和最新的Derby。
请帮忙