Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import sqlalchemy
  2. import pyodbc
  3.  
  4. print('hello world')
  5.  
  6. connection = pyodbc.connect('Driver={SQL Server};Server=.\\SQLSTANDARD;;Database=MarcinDB;uid=marcin;pwd=marcin')
  7.  
  8. print("Połączono")
  9.  
  10. cursor = connection.cursor()
  11.  
  12.  
  13. #sql_command = ("CREATE TABLE Osoby ( staff_number INTEGER PRIMARY KEY, imie VARCHAR(20),nazwisko VARCHAR(30),mail VARCHAR(40));")
  14.  
  15. #cursor.execute(sql_command)
  16.  
  17.  
  18.  
  19. sql_command = ("""INSERT INTO Osoby (staff_number, imie, nazwisko, mail)
  20.              VALUES (4, 'Anna', 'Karenina', 'anna@ja.pl');""")
  21.  
  22. cursor.execute(sql_command)
  23. cursor.commit()
  24. sql_command = ("""INSERT INTO Osoby (staff_number, imie, nazwisko, mail)
  25.              VALUES (2, 'Jacek', 'Placek', 'jacek@placek.pl');""")
  26.  
  27. cursor.execute(sql_command)
  28. cursor.commit()
  29. # SQL Query
  30. """
  31. SQLCommand = ("select * from CUSTOMERS")
  32. # Processing Query
  33. cursor.execute(SQLCommand)
  34. i = 1
  35. for rows in cursor.fetchall():
  36.    print("------------CUSTOMERS %d-----------------" % i)
  37.    for field in rows:
  38.        print(str(field))
  39.    print("---------------------------------------")
  40.    print('')
  41.    i = i + 1
  42. """
  43.  
  44. # closing connection
  45. connection.close()
  46. print("Zamknięto połączenie")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement