Getting the values from the database and Error handling

suggest change

Fetching the values from the SQLite3 database.

Print row values returned by select query

import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("SELECT * from table_name where id=cust_id")
for row in c:
    print row # will be a list

To fetch single matching fetchone() method

print c.fetchone()

For multiple rows use fetchall() method

a=c.fetchall() #which is similar to list(cursor) method used previously
for row in a:
    print row

Error handling can be done using sqlite3.Error built in function

try:
    #SQL Code
except sqlite3.Error as e:
    print "An error occurred:", e.args[0]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


SQLite3 module:
* Getting the values from the database and Error handling

Table Of Contents
2 Filter
3 List
7 Loops
22 Reduce
27 Classes
31 Set
42 Tuple
45 Enum
62 Sockets
89 urllib
92 Idioms
104 Stack
105 Profiling
109 Logging
111 os module
118 Mixins
120 ArcPy
126 Arrays
132 2to3 tool
135 Unicode
138 Neo4j
140 Curses
141 Templates
145 heapq
146 tkinter
149 SQLite3 module
154 Audio
155 pyglet
157 ijson
160 Flask
161 Groupby
163 pygame
165 hashlib
166 Gzip
167 ctypes
185 pyaudio
186 shelve