# 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= cx_Oracle.connect('用户名', '密码', 'ip:1521/oracle的serve_name')
cursor=db.cursor()''' rows = cursor.execute('select * from table')for sz inrows:
print sz'''try:
all_the_text=file_object.read()
jsonVal=json.loads(all_the_text)
param=[]for val injsonVal:
#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(server_id, server_name, chinese_name) values(:1, :2, :3)') # 一次插入全部数据
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()