我使用以下代码查询我的MySQL数据库。
public static String epochToFormatted(Long epoch) {
SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");
return sdf.format(new Date(epoch));
}
问题是import MySQLdb
db = MySQLdb.connect("localhost","user","password","test" )
cursor = db.cursor(MySQLdb.cursors.DictCursor)
sql = "select * from student"
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
print row['firstname']
except:
print "Error: unable to fecth data"
db.close()
中指定的列名称不匹配且区分大小写。有没有办法忽略区分大小写?
答案 0 :(得分:1)
你可以用这个:
sequence = cursor.column_names
http://php.net/manual/en/function.in-array.php
然后使用.lower()将您的字符串与实际名称进行比较,并相应地采取行动