파이썬에서 다른 것보다 효율적입니다. 내 요구 사항은 응용 프로그램을 종료 할 때까지 하나의 연결을 갖는 것입니다.파이썬에서의 커서 대 연결
나는 두 개의 클래스를 하나씩 만들어서 연결/커서를 사용하고 내 서비스에서 데이터를 가져와 가져올 수 있습니다. 그래서 내 혼란,
Connection Established
Connection Established
In method getStudentdata()
[(1, 2021, 2, Decimal('4.00')), (2, 2030, 2, Decimal('3.50')),... ]
++++++++++++++++++++++++++++++++
In method getcursorstudentdata()
[(1, 2021, 2, Decimal('4.00')), (2, 2030, 2, Decimal('3.50')),... ]
입니다
import pyodbc
class Connection:
def getconnection(self):
conn = pyodbc.connect('Driver={SQL Server};Server=.\SQLEXPRESS;Database=School;Trusted_Connection=yes;')
print("Connection Established")
#cursor = conn.cursor()
return conn
def getcursor(self):
conn = pyodbc.connect('Driver={SQL Server};Server=.\SQLEXPRESS;Database=School;Trusted_Connection=yes;')
print("Connection Established")
cursor = conn.cursor()
return cursor
하나의 서비스 클래스를 파이썬 :
한 DBConnection 클래스에
import Connection
import pyodbc
class StudentDataService:
connection = Connection.Connection().getconnection()
cursor = Connection.Connection().getcursor()
def getstudentdata(self):
print("In method getStudentdata()")
try:
row = self.connection.execute('select * from StudentGrade')
studentList = list(row)
return studentList
except pyodbc.DatabaseError as err:
print("Error Occurred while fetching Student Records", err)
return None
finally:
self.connection.close()
def getcursorstudentdata(self):
print("In method getcursorstudentdata()")
try:
row = self.cursor.execute('select * from StudentGrade')
studentList = list(row)
return studentList
except pyodbc.DatabaseError as err:
print("Error Occurred while fetching Student Records", err)
return None
finally:
self.cursor.close()
stu = StudentDataService()
print(stu.getstudentdata())
print("++++++++++++++++++++++++++++++++")
print(stu.getcursorstudentdata())
을 MVC에 따라 그리고 모두가 나에게주는 것은 어떤 결과 하나?