Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Db2存储数据时遇到数字文本XXXX错误,该错误无效_Python_Sql_Db2 - Fatal编程技术网

Python Db2存储数据时遇到数字文本XXXX错误,该错误无效

Python Db2存储数据时遇到数字文本XXXX错误,该错误无效,python,sql,db2,Python,Sql,Db2,我正在解析邻居以及邻居的纬度和经度,并将其存储到IBMDB2中。我遇到了以下错误代码。请告知 导入版本如下所示 ibm_db 3.0.2 requests 2.24.0 bs4 4.9.1 pandas 1.0.5 primary_key = 0 for table in soup.find_all('table', class_ = 'multicol'): for neighbour in table.find_all('a', href=True, class_=False):

我正在解析邻居以及邻居的纬度和经度,并将其存储到IBMDB2中。我遇到了以下错误代码。请告知

导入版本如下所示

ibm_db 3.0.2
requests 2.24.0
bs4 4.9.1
pandas 1.0.5
primary_key = 0
for table in soup.find_all('table', class_ = 'multicol'):
    for neighbour in table.find_all('a', href=True, class_=False):
        url2 = 'https://en.wikipedia.org/' + neighbour['href']
        url_object = requests.get(url2)
        soup2 = BeautifulSoup(url_object.text, 'html.parser')
        count = 0
        primary_key += 1
        for coor in soup2.find_all('span', class_ = ['latitude','longitude']):
            if count == 2: continue
            if count == 0: lat = str(coor.string)
            if count == 1: lng = str(coor.string)
            count += 1
        print(primary_key,url2, neighbour['title'],lat, lng)
        insertQuery = f"insert into TORONTO values({primary_key},'{neighbour['title']}','{url2}','{lat}','{lng}')" 
        ibm_db.exec_immediate(conn,insertQuery)
我能够按照以下方式解析项目102:

失败位置的HTML:

错误代码

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-9-035d46749936> in <module>
     14         print(primary_key,";",neighbour['href'],";", neighbour['title'],";",lat, lng)
     15         insertQuery = f"insert into TORONTO values({primary_key},'{neighbour['title']}','{neighbour['href']}','{lat}','{lng}')"
---> 16         ibm_db.exec_immediate(conn,insertQuery)

Exception: [IBM][CLI Driver][DB2/LINUXX8664] SQL0103N  The numeric literal "27s_Bridge" is not valid.  SQLSTATE=42604 SQLCODE=-103

尝试将查询更改为:

insertQuery=f“插入多伦多值({primary_key},{nexture['title']},{url2},{lat},{lng}')”

名为Toronto的表?!?为每个城市单独安排一张桌子是一个非常糟糕的主意。只为一次作业。我需要找出Toronto中的所有邻居,请编辑您的问题,以显示您使用的组件的版本(以及python代码中的
import…
列表),例如从
pip freeze
等添加的导入版本。谢谢你的建议。嗨,谢谢。它起作用了。我可以知道为什么需要将“”添加到变量中吗?我认为所有字符串都已经是表模式指定的字符串了?SQL与python类似,因为所有字符串都需要用引号/撇号括起来,仅仅引用变量是不够的,您需要在引号/撇号中硬编码。哦,明白了。因此,即使变量为string,仍然不够。Hi。我有一个新的错误代码
[IBM][CLI Driver][DB2/LINUXX8664]SQL0103N数字文字“27s_桥”无效。SQLSTATE=42604 SQLCODE=-103
它发生在观察时#103您是否能够共享SQL insert语句试图使用值而不是变量名运行的确切信息?