반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- docker
- or some instances in your deployment group are experiencing problems.
- Kafka
- kubeflow
- codepipeline
- chart.js
- COALESCE
- PostgreSQL
- Python
- java bigdecimal
- aws
- chartjs
- node
- IntelliJ
- AWS CI/CD 구축하기
- Flux
- Airflow
- Jenkins
- redis
- 도커
- aws cicd
- SQL
- JavaScript
- Spring
- bootstrap
- Spring Error
- codebuild
- VPN
- codedeploy error
- codedeploy
Archives
- Today
- Total
Small Asteroid Blog
[python] python db select 문 출력하기 본문
728x90
python과 db 를 연결한 내용은 conn 이다.
execute 메서드를 호출해 sql명령어를 입력한다.
cur = conn.cursor()
cur.execute("select * from ptck.news_save ")
cr = cur.fetchall()
for x in cr:
print(x)
함수로 sql 문을 사용하는 방법이다.
cur 은 db connect 에 대한 내용이다.
위의 cur = conn.cursor() 로 보면된다.
#함수로 필요한 데이터 호출
def readDB(self,schema,table,colum):
sql = "select {colum} from {schema}.{table}".format(colum=colum,schema=schema,table=table)
try:
self.execute(sql)
result = self.fetchall()
except Exception as e:
result = (" read DB error ",e)
return result
print(readDB(cur,schema="test",table="news",colum="*"))
print(readDB(cur,"test","news","*"))
728x90
반응형