Unable to perform NamedParameterJdbcTemplate UPDATE - spring-jdbc

I am trying to perform an UPDATE to a SnappyData row table via JDBC APIs and Spring's NamedParameterJdbcTemplate.
Error is:
Caused by: java.sql.SQLException: **(SQLState=XCL14 Severity=20000) The column position '1' is out of range. The number of columns for this ResultSet is '0'.**
at com.pivotal.gemfirexd.internal.shared.common.error.DefaultExceptionFactory40.getSQLException(DefaultExceptionFactory40.java:121)
at com.pivotal.gemfirexd.internal.shared.common.error.ExceptionUtil.newSQLException(ExceptionUtil.java:148)
at com.pivotal.gemfirexd.internal.client.am.SqlException.getSQLException(SqlException.java:419)
at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.getColumnType(ColumnMetaData.java:644)
at com.pivotal.gemfirexd.internal.client.am.PreparedStatement.setString(PreparedStatement.java:1203)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:429)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:150)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:292)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:244)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:623)
... 70 more
Caused by: ERROR XCL14: The column position '1' is out of range. The number of columns for this ResultSet is '0'.
at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.checkForValidColumnIndex(ColumnMetaData.java:856)
at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.getColumnType(ColumnMetaData.java:638)
The NamedParameter SQL looks like this:
UPDATE generic_table_10 SET (VERSION = :version, FK_1 = :fk , COL_1 = :col1, COL_2 = :col2, COL_3 = :col3, COL_4 = :col4, COL_5 = :col5, COL_6 = :col6, COL_7 = :col7, COL_8 = :col8, COL_9 = :col9, COL_10 = :col10) WHERE (ID = :id and VERSION = :oldVersion)
NOTE: VERSION column type is an Integer. All the rest of the column
types are String.
The SQL looks like this, which seems alright to me:
UPDATE generic_table_10 SET (VERSION = ?, FK_1 = ? , COL_1 = ?, COL_2 = ?, COL_3 = ?, COL_4 = ?, COL_5 = ?, COL_6 = ?, COL_7 = ?, COL_8 = ?, COL_9 = ?, COL_10 = ?) WHERE (ID = ? and VERSION = ?)

I resolved this myself... The syntax is bad. I removed the parenthesis and it works now. Here is the SQL now:
UPDATE generic_table_10 SET VERSION = ?, FK_1 = ? , COL_1 = ?, COL_2 = ?, COL_3 = ?, COL_4 = ?, COL_5 = ?, COL_6 = ?, COL_7 = ?, COL_8 = ?, COL_9 = ?, COL_10 = ? WHERE ID = ? and VERSION = ?
I must say, despite my lack of SQL syntax skills, the error message was a bit misleading!

Related

PeopleSoft Subquery not picking up correct leave plans

I'm attempting to build a report in PeopleSoft's Query Manager that has future and current employees on it. I want to be able to find the employees who do not have leave plans, specifically 50 and 52. I thought I was on the right track with the following BUT after auditing my report it is bringing in people who HAVE 50 and 52. I think it has to do with the subquery (SQL below).
Here are some pictures of query manager:
SELECT DISTINCT B.COMPANY, A.EMPLID, A.NAME, B.FULL_PART_TIME, B.REG_TEMP, C.DESCR, D.PLAN_TYPE, (CASE WHEN B.REG_TEMP = 'T' THEN '' WHEN C.DESCR = 'Intern' THEN '' WHEN C.DESCR = 'PenFed Intern' THEN '' ELSE 'Check records/give Leave' END), CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121)), (CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121)), (CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121))
FROM (PS_PERSONAL_DATA A LEFT OUTER JOIN (PS_LEAVE_PLAN D INNER JOIN PS_EMPLMT_SRCH_QRY D1 ON (D.EMPLID = D1.EMPLID AND D.EMPL_RCD = D1.EMPL_RCD AND D1.OPRID = 'XXXXXXXX' )) ON A.EMPLID = D.EMPLID ), PS_PFC_JOB_VW B, PS_JOBCODE_TBL C, PS_SET_CNTRL_REC C2
WHERE ( C.JOBCODE = B.JOBCODE
AND C2.SETCNTRLVALUE = B.BUSINESS_UNIT
AND C2.RECNAME = 'JOBCODE_TBL'
AND C2.SETID = C.SETID
AND ( A.EMPLID = B.EMPLID
AND ( B.EFFDT =
(SELECT MAX(B_ED.EFFDT) FROM PS_PFC_JOB_VW B_ED
WHERE B.EMPLID = B_ED.EMPLID
AND B.EMPL_RCD = B_ED.EMPL_RCD
AND B_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND B.EFFSEQ =
(SELECT MAX(B_ES.EFFSEQ) FROM PS_PFC_JOB_VW B_ES
WHERE B.EMPLID = B_ES.EMPLID
AND B.EMPL_RCD = B_ES.EMPL_RCD
AND B.EFFDT = B_ES.EFFDT)
OR ( B.EFFDT =
(SELECT MIN(B_ED.EFFDT) FROM PS_PFC_JOB_VW B_ED
WHERE B.EMPLID = B_ED.EMPLID
AND B.EMPL_RCD = B_ED.EMPL_RCD
AND B_ED.EFFDT >= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND B.EFFSEQ =
(SELECT MAX(B_ES.EFFSEQ) FROM PS_PFC_JOB_VW B_ES
WHERE B.EMPLID = B_ES.EMPLID
AND B.EMPL_RCD = B_ES.EMPL_RCD
AND B.EFFDT = B_ES.EFFDT)
AND B.ACTION IN ('HIR','REH','REI')))
AND B.EMPL_STATUS IN ('A','L','P')
AND B.PER_ORG = 'EMP'
AND C.EFFDT =
(SELECT MAX(C_ED.EFFDT) FROM PS_JOBCODE_TBL C_ED
WHERE C.SETID = C_ED.SETID
AND C.JOBCODE = C_ED.JOBCODE
AND C_ED.EFFDT <= B.EFFDT)
AND A.EMPLID NOT IN (SELECT E.EMPLID
FROM PS_LEAVE_PLAN E, PS_EMPLMT_SRCH_QRY E1
WHERE E.EMPLID = E1.EMPLID
AND E.EMPL_RCD = E1.EMPL_RCD
AND E1.OPRID = 'XXXXXXXX'
AND ( E.EFFDT =
(SELECT MAX(E_ED.EFFDT) FROM PS_LEAVE_PLAN E_ED
WHERE E.EMPLID = E_ED.EMPLID
AND E.EMPL_RCD = E_ED.EMPL_RCD
AND E.PLAN_TYPE = E_ED.PLAN_TYPE
AND E.BENEFIT_NBR = E_ED.BENEFIT_NBR
AND E_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND ( E.PLAN_TYPE = '50'
OR E.PLAN_TYPE = '52') )) ))
Where am I going wrong here?

Storing user objects in Session

I have a User entity. One user can buy a product. After the form validation I want to store the user data (ID, name, mail, password, address, ..) in $session, and only after the success payment retrieve this data from session and store it to the db.
This is what I'm doing: (if the from is valid)
$session = new Session();
$serialized_user = serialize($user);
$session->set('myuser', ($serialized_user));
Then, after the payment check:
$test = ($this->get('session')->get('myuser'));
$test_unserialized = unserialize($test);
$em = $this->getDoctrine()->getManager();
$em->persist($test_unserialized);
$em->flush();
return $this->render('UserBundle:Account:buyedOk.php');
What I got is this error:
An exception occurred while executing 'INSERT INTO user (user, passw, email, is_active, is_locked, date_expire, date_registration, last_visit, name, surname, address, zipcode, city, province, country, vat, tel, fax, contact_name, contact_role, contact_email, contact_tel, email_hex, email_confirmed, validated,id_currency) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["March", "$2y$13$hTBP0ANwRlwgcfX19OtsTubn6ctI64lz5GVQ3JF3nZtD0GDPK8rTC", null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null
Suggestions?

Add columns to Power Query from Google Analytics

I'm using Kohera's Power Pivot Formula to get Google Analytics data in Power Query:
let
analytics = "https://www.googleapis.com/analytics/v3/data/ga?access_token=",
addAccessToken = analytics &
Excel.CurrentWorkbook(){[Name="TblToken"]}[Content]{0}[Access Token],
addViewId = addAccessToken & "&ids=ga:33784873",
addStartDate = addViewId & "&start-date=2014-10-01",
addEndDate = addStartDate & "&end-date=2014-12-31",
addDimensions = addEndDate & "&dimensions=ga:operatingSystem",
url = addDimensions & "&metrics=ga:sessions",
GaJson = Json.Document(Web.Contents(url)),
GetRows = GaJson[rows],
TableFromList = Table.FromList(GetRows, Splitter.SplitByNothing(),
null, null, ExtraValues.Error),
ColOS = Table.AddColumn(TableFromList, "OS", each [Column1]{0}),
ColCount = Table.AddColumn(ColOS, "Count", each [Column1]{1}),
RemoveFirstColumn = Table.RemoveColumns(ColCount,{"Column1"}) in RemoveFirstColumn
However, how do I add more columns? For example, if I wanted to do a query for ga:hostname,ga:country,ga:browser, how would I get this in M code?
Thank you!
OK, I've figured it out. To explain for others:
TableFromList = Table.FromList(GetRows, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ColHostname = Table.AddColumn(TableFromList, "Hostname", each [Column1]{0}),
ColCountry = Table.AddColumn(ColHostname, "Country", each [Column1]{1}),
ColBrowser = Table.AddColumn(ColCountry, "Browser", each [Column1]{2}),
ColCount = Table.AddColumn(ColBrowser, "Count", each [Column1]{3}),
RemoveFirstColumn = Table.RemoveColumns(ColCount,{"Column1"})

Must declare the scalar variable "#useridaUPDATE"

sqlqrystrng = "UPDATE temp_user_details set user_name = #username, user_email = #useremail, user_contact = #usercontact, user_address=#useraddress WHERE user_id = #userida"
sqlqrystrng2 = "UPDATE user_type set user_password = #userpassword where user_id = #useridb"
string_cnct = sqlqrystrng & sqlqrystrng2
conn.open
cmd = New SqlCommand(string_cnct, conn)
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#userida"
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#useridb"
cmd.Parameters.Item("#userida").Value = struserid
cmd.Parameters.Item("#useridb").Value = struserid
sqlqrystrng = "UPDATE temp_user_details set user_name = #username, user_email =
useremail, user_contact = #usercontact, user_address=#useraddress WHERE user_id =
userida"
sqlqrystrng2 = " UPDATE user_type set user_password = #userpassword where user_id = #useridb"
string_cnct = sqlqrystrng & sqlqrystrng2
conn.open
cmd = New SqlCommand(string_cnct, conn)
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#userida"
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#useridb"
cmd.Parameters.Item("#userida").Value = struserid
cmd.Parameters.Item("#useridb").Value = struserid
You need to add space before Update in second string

ORA-00947: not enough values

I get an error "ORA-00947: not enough values") inserting a record and can't see why! It seems to me I have the correct number of parameters:
string sQuery = "insert into EventLog (UserEventLogID, USERID, EVENTSEVERITYID, LOGTIME_TZ, USEREVENTTYPEID, USEREVENTMSG) " +
"values (0, :USERID, :EVENTSEVERITYID, cast(:LOGTIME_TZ as Timestamp(6) With Time Zone) at time zone '" + oLog.TimeZone + "'), " +
":EVENTTYPEID, :EVENTMSG) " +
" returning USEREVENTLOGID into :EventLogID";
oraCmd = new OracleCommand();
oraCmd.BindByName = true;
oraCmd.Parameters.Add("EVENTSEVERITYID", OracleDbType.Int16, 2, oLog.EventSeverityID, ParameterDirection.Input);
oraCmd.Parameters.Add("LOGTIME_TZ", OracleDbType.TimeStamp, 6, oLog.EventTimestamp, ParameterDirection.Input);
oraCmd.Parameters.Add("EVENTTYPEID", OracleDbType.Int16, 4, oLog.EventTypeID, ParameterDirection.Input);
oraCmd.Parameters.Add("EVENTMSG", OracleDbType.Varchar2, 300, oLog.EventMsg, ParameterDirection.Input);
oraCmd.Parameters.Add("USERID", OracleDbType.Varchar2, 50, oLog.UserID, ParameterDirection.Input);
outParam = new OracleParameter("EventLogID", OracleDbType.Decimal);
outParam.Direction = ParameterDirection.Output;
oraCmd.Parameters.Add(outParam);
the table has one more column "LGTIME" which is nullable so I did not include it in insert statement.
I see an extra ")" .
cast(:LOGTIME_TZ as Timestamp(6) With Time Zone) <----- at time zone '" + oLog.TimeZone + "')

Resources