Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.sql.*;
  2. public class Baza{
  3.     public static void main(String[] args) {
  4.        
  5.    
  6.        
  7.         Connection conn = null;
  8.        
  9.         try {
  10.          
  11.             Class.forName("com.mysql.jdbc.Driver");
  12.        
  13.            
  14.             conn = DriverManager.getConnection("jdbc:mysql://localhost/ksiegarnia","root","");
  15.            
  16.            
  17.            
  18.             Statement sqlState = conn.createStatement();
  19.            
  20.            
  21.            
  22.             String selectStuff = "Select klienci.imie,klienci.nazwisko FROM klienci,zamowienia ";
  23.            
  24.          
  25.            
  26.             ResultSet rows = sqlState.executeQuery(selectStuff);
  27.            
  28.             int i=0;
  29.             while(rows.next()){
  30.                 System.out.println(rows.getString("imie")+" "+rows.getString("nazwisko"));
  31.                 i++;
  32.                
  33.             }
  34.             System.out.println(i);
  35.         }
  36.        
  37.         catch (SQLException ex) {
  38.            
  39.             System.out.println("SQLException: " + ex.getMessage());
  40.            
  41.                        
  42.             System.out.println("VendorError: " + ex.getErrorCode());
  43.         }
  44.        
  45.         catch (ClassNotFoundException e) {
  46.            
  47.             e.printStackTrace();
  48.         }
  49.        
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement