我是一个新的jython脚本。我想把 SELECT
查询到一个变量中。选择查询的输出只是 "2020"
. 我试图将其存储在一个名为 YEAR
但下面的代码却失败了。
The Entire script goes like below . I am able to establish the connection and select query is also working , But not sure how to capture output of query "2020" in "YEAR" Variable .Please note iam not using MYSQL, it is ORALCE SQL DEVELOPER database
import string
import java.math.BigDecimal as BigDecimal
import java.lang as lang
import java.sql as sql
import time
import os
import shutil
import string
import csv
strJDBCURL = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=YES)(FAILOVER=YES)"
strJDBCURL += "(ADDRESS=(PROTOCOL=tcp)(HOST = xxxxx)(PORT=xxxx))"
strJDBCURL += "(ADDRESS=(PROTOCOL=tcp)(HOST = xxxxx)(PORT=xxxx)))"
strJDBCURL += "(CONNECT_DATA=(SERVICE_NAME = xxxxxx)))
EAConn = sql.DriverManager.getConnection (strJDBCURL, "USERNAME", "PASSWORD");
selectStmt = "SELECT COLUMN_NAME FROM table_name WHERE COLUMN_NAME ='xxxxx'"
stmt = EAConn.prepareStatement(selectStmt)
rs = stmt.execute()
YEAR = rs.fetchall() |error :AttributeError: 'bool' object has no attribute 'fetchall'
i have also tried below formats ,which are also giving errors
YEAR = RS.getBigDecimal("YEAR") |error : AttributeError: 'bool' object has no attribute 'getBigDecimal'
YEAR = rs.getBigDecimal(String YEAR) |error : SyntaxError: no viable
^
alternativeat input 'YEAR'
YEAR = rs.fetchall(String YEAR) |error : SyntaxError: no viable alternative at
^
input 'YEAR'
作为最后一行在你的代码片段尝试。
YEAR = rs.getBigDecimal("YEAR")
不加类型指定符 String
. Jypthon 是动态类型化的;作为 Python 2 的变体,它不允许在参数列表中包含任何类型信息。