Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public SudokuBoard read() throws MySQLException, WrongValueException, WrongIndexException {
- try {
- Connection connection = DriverManager.getConnection("jdbc:derby:SudokuDB;create=false;user=test;password=test:");
- Statement stm = connection.createStatement();
- ResultSet r = stm.executeQuery("select max(board) as m from fields");
- int board;
- if (r.next()) {
- board = r.getInt("m");
- } else {
- board = 0;
- }
- r = stm.executeQuery("select posx as x, poxy as y value as v from fields where board=" + Integer.toString(board));
- SudokuBoard brd = new SudokuBoard();
- while (r.next()) {
- int iks = r.getInt("x");
- int igrek = r.getInt("y");
- int val = r.getInt("v");
- brd.set(iks, igrek, val);
- }
- connection.close();
- return brd;
- } catch (SQLException e) {
- throw new MySQLException("Problem with Database");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement