Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public SudokuBoard read() throws MySQLException, WrongValueException, WrongIndexException {
  2.         try {
  3.             Connection connection = DriverManager.getConnection("jdbc:derby:SudokuDB;create=false;user=test;password=test:");
  4.             Statement stm = connection.createStatement();
  5.             ResultSet r = stm.executeQuery("select max(board) as m from fields");
  6.             int board;
  7.             if (r.next()) {
  8.                 board = r.getInt("m");
  9.             } else {
  10.                 board = 0;
  11.             }
  12.             r = stm.executeQuery("select posx as x, poxy as y value as v from fields where board=" + Integer.toString(board));
  13.  
  14.             SudokuBoard brd = new SudokuBoard();
  15.             while (r.next()) {
  16.                 int iks = r.getInt("x");
  17.                 int igrek = r.getInt("y");
  18.                 int val = r.getInt("v");
  19.                 brd.set(iks, igrek, val);
  20.             }
  21.             connection.close();
  22.             return brd;
  23.         } catch (SQLException e) {
  24.             throw new MySQLException("Problem with Database");
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement