# coding=utf-8 ''''' Created on 2020-01-05 @author: Mr. Zheng ''' import json; import urllib2 import sys import cx_Oracle import exceptions # page=urllib2.urlopen("http://").read() # jsonVal = json.loads(page) def read_json_file(file_name): file_object = open(file_name) DB = the cx_Oracle.connect ( ' username ' , ' password ' , ' IP: 1521 / Oracle's serve_name ' ) cursor = db.cursor() ''' rows = cursor.execute('select * from table') for sz in rows: No print ''' try: all_the_text = file_object.read() jsonVal = json.loads(all_the_text) param = [] for val in jsonVal: #print val["serverid"] #print val["server_name"] param.append((val["serverid"], "san_s" + val["serverid"], val["server_name"])) # cursor.execute('insert into game_server_name(server_id, server_name, chinese_name) values(:server_id, :2, :3)',(val["serverid"], "san_s" + val["serverid"], val["server_name"])) # cursor.execute("insert into game_server_name(server_id, server_name, chinese_name) values('a','b','c')") print param print len (param) cursor.prepare ( ' INSERT INTO game_server_name (the server_id, server_name, chinese_name) values (:. 1,: 2,:. 3) ' ) inserted once all the data # cursor.executemany(None, param) db.commit() except Exception, err: print err finally: cursor.close() db.close() file_object.close() def main(): read_json_file('E:/android.json') read_json_file('E:/apple.json') if __name__ == '__main__': main()
When only one parameter, but also to have it written in the form of tuples:
例如:Cursor.execute(‘select name from user where id=:1’,(login_Id,))
Do pay attention: back login_id also comes with a comma