Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public synchronized String pobierzStatystyki(){
- Connection c = null;
- Statement stat = null;
- String wynik = "";
- try {
- Class.forName("org.sqlite.JDBC");
- c = DriverManager.getConnection("jdbc:sqlite:statystyki.db");
- stat = c.createStatement();
- String comenda = "SELECT * FROM STATYSTYKI";
- ResultSet result = stat.executeQuery(comenda);
- while(result.next()){
- wynik += result.getString("UZYTKOWNIK");
- wynik += "\n";
- wynik += result.getInt("PUNKTY");
- wynik += "\n";
- }
- stat.close();
- c.close();
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return wynik;
- }
- public synchronized void dodajStatystyke(String nazwa,int punkty){
- Connection c = null;
- Statement stat = null;
- try {
- Class.forName("org.sqlite.JDBC");
- c = DriverManager.getConnection("jdbc:sqlite:statystyki.db");
- stat = c.createStatement();
- String comenda;
- /*comenda = "DROP TABLE STATYSTYKI";
- try{
- stat.executeUpdate(comenda);
- }catch(Exception ex){
- }*/
- try{
- comenda = "CREATE TABLE STATYSTYKI("
- + "UZYTKOWNIK TEXT,"
- + "PUNKTY INTEGER"
- + ");";
- stat.executeUpdate(comenda);
- }catch(Exception ex){
- //ex.printStackTrace();
- }
- comenda = "INSERT INTO STATYSTYKI VALUES ("
- + "'"+ nazwa + "',"
- + punkty
- + ");";
- stat.executeUpdate(comenda);
- stat.close();
- c.close();
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement