Advertisement
Guest User

laczenie z bazą danych

a guest
Jan 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. public class DemoDB {
  6. public static void main(String[] args) {
  7. try{
  8. Class.forName("org.postgresql.Driver");
  9. Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres","1234567890");
  10. PreparedStatement stmt = con.prepareStatement("select kolor from auta");
  11. ResultSet Rs = stmt.executeQuery();
  12. while (Rs.next()) {
  13. System.out.println(Rs.getInt(1)+" "+Rs.getString(2));
  14. }
  15.  
  16.  
  17. } catch(Exception ex){
  18. System.out.println(ex.getMessage());
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement