SHARE
TWEET

Untitled

a guest Jan 20th, 2020 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package yhteystietosovellus;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.Statement;
  12. import java.util.ArrayList;
  13.  
  14. /**
  15.  *
  16.  * @author sami.laaksonen
  17.  */
  18. public class JModel {
  19.     ArrayList<JAsiakas> getClients()
  20.     {
  21.         ArrayList<JAsiakas> asiakkaat = new ArrayList<>();
  22.         try{  
  23.             Class.forName("com.mysql.jdbc.Driver");  
  24.             Connection con=DriverManager.getConnection(  
  25.             "jdbc:mysql://localhost:3306/yhteystiedot","root","");  
  26.             //here sonoo is database name, root is username and password  
  27.             Statement stmt=con.createStatement();  
  28.             ResultSet rs=stmt.executeQuery("select * from asiakas");  
  29.             while(rs.next())
  30.             {
  31.                 JAsiakas asiakas = new JAsiakas();
  32.                 asiakas.setId(rs.getInt("asiakasid"));
  33.                 asiakas.setNimi(rs.getString("nimi"));
  34.                 asiakas.setOsoite(rs.getString("osoite"));
  35.                 asiakas.setPuhelin(rs.getString("puhelinnumero"));
  36.                 asiakas.setEmail(rs.getString("email"));
  37.                 asiakkaat.add(asiakas);
  38.             }
  39.             //System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
  40.             con.close();
  41.         }catch(Exception e){ System.out.println(e);}  
  42.         return asiakkaat;
  43.     }    
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top