Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class SQL
  9. {
  10. {
  11. String url = "jdbc:mysql://localhost:3306/";
  12. String user = "root";
  13. String password = "";
  14.  
  15. try
  16. {
  17. Class.forName("com.mysql.jdbc.Driver").newInstance();
  18. Connection con = DriverManager.getConnection(url, user, password);
  19. Statement stt = con.createStatement();
  20. stt.execute("USE test");
  21.  
  22.  
  23. ResultSet res = stt.executeQuery("SELECT * FROM osoba WHERE nazwisko = 'nowak'");
  24.  
  25. stt.execute("INSERT INTO osoba(imie, nazwisko, wiek, pesel) VALUES" +
  26. "('jan', 'nowak', 25, 99999)");
  27.  
  28.  
  29.  
  30.  
  31.  
  32. res.close();
  33. stt.close();
  34. con.close();
  35.  
  36. }
  37. catch (Exception e)
  38. {
  39. e.printStackTrace();
  40. }
  41.  
  42. }
  43. //------------------------------
  44. public void dodaj_osobe()
  45. {
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement