SHARE
TWEET

d

a guest Feb 28th, 2020 75 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 pab_lab1_grs2232;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.Statement;
  12. import javax.swing.JOptionPane;
  13.  
  14. public class BazaDanych {
  15.     public void baza(){
  16.         try{
  17.             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  18.             Connection polaczenie = DriverManager.getConnection("jdbc:sqlserver://localhost\\MSSQLServer2017;databaseName=S2232","sa","student");
  19.             Statement skladnia = polaczenie.createStatement();
  20.             ResultSet rezultat = skladnia.executeQuery(
  21.                     "select nazwa, cena from dane"
  22.             );
  23.             while(rezultat.next()){
  24.                 System.out.println(rezultat.getString("nazwa")+" "+rezultat.getString("cena"));
  25.             }
  26.             polaczenie.close();
  27.         }
  28.         catch(Exception ex){
  29.             JOptionPane.showMessageDialog(null,"Błąd"+ex.getMessage(),"Błąd programu", JOptionPane.ERROR_MESSAGE);
  30.         }
  31.     }
  32. }
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