I'm about to rip my hair out with this one.
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
The error occurred in [WITHHELD]: line 19
17 : WHERE FNAME = #FORM.first#
18 : AND LNAME = #FORM.last#
19 : AND PASS = #FORM.pass#
20 : </cfquery>
21 :
SQLSTATE 07002
SQL SELECT * FROM JUDGES WHERE FNAME = [WITHHELD] AND LNAME = [WITHHELD] AND PASS = [WITHHELD]
VENDORERRORCODE -3010
DATASOURCE honors
I've read a number of similar issues where there was some spelling error but I've checked and rechecked spellings, even changed column and table names and tried again.
Ensure that you quote your variables:
where FNAME = '#FORM.first#'
Additionally, you should really use cfqueryparam to protect against SQL injection attacks:
where FNAME = <cfqueryparam value="#FORM.first#" cfsqltype="CF_SQL_VARCHAR">
(Note that you do not need the quotes when using cfqueryparam)
cfqueryparam documentation
a note about MS Access support for cfqueryparam
Related
I intend to do:
EXECUTE('UPDATE tableA SET campaignkey = ''20170101'' where storekey = 16
and campaignkey LIKE ''%,%''') at MYLINKEDSERVER
but I get the error that:
You have an error in your SQL syntax; [...] for the right syntax to use near 'where storekey = 16 and campaignkey LIKE '%,%''
Does anyone have any idea what is wrong? To me it seems like I might have one ' too many on my LIKE statement, but I have Always used '' to indicate a non-numeric value. I don't want to fiddle with this to prevent updating far too many values on this server.
campaignkey is non-numeric (I Believe varchar) and storekey is integer.
Edit
I must not use OPENQUERY() because it is not set up correctly, and this is a urgent update.
Edit 2
Seems like it is because of apostrophes 's in the EXECUTE statement.
When I conduct:
select * from openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
it works, but when using:
EXECUTE('Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''') at linkedserver
I get the error that I need to check the manual by the where clause. From googling it appears however that the correct syntax in fact is:
EXECUTE('UPDATE TableX SET StringVar = ''stringValue'' WHERE intVar = 3
AND stringVar = ''xxxxx''') AT LinkedServer
I don't know why this won't work for me.. I have tried many combinations of '', '" etc.
What about this one?
update openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
set campaignkey = '20170101'
I tried running this sql
UPDATE table
SET read = 1
WHERE col1_id = 2
AND col3_id = 1;
and it return an error (error in your sql syntax)
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read = 1 WHERE team_notification_id = 2 AND listener_id = 1' at line 1
But when I used thesame WHERE and AND :), in a SELECT statement no error was returned.
SELECT *
FROM read
WHERE col1_id = 2
AND col3_id = 1
please what did I do wrong, I am no seeing it.
After keyword UPDATE there should be a table name. If your table has actually name table (that's a bit strange) you should escape it to let MySQL know it's not a keyword "table" but actual table name.
The same thing is about read.
Both table and read are MySQL keywords (the full list is here http://dev.mysql.com/doc/refman/5.7/en/keywords.html) so if it's your actual table and column names then you should escape it.
Better to escape all table and column names to prevent issues like that.
Escaping in MySQL is done with backtick symbol ` so your query will looks like:
UPDATE `table`
SET `read` = 1
WHERE `col1_id` = 2
AND `col3_id` = 1;
UPDATE tablename
SET `field_name` = 1
WHERE col1_id = 2
AND col3_id = 1;
UPDATE table
SET [read] = 1
WHERE col1_id = 2
AND col3_id = 1;
I have this legacy code that started failing…
UPDATE B2C
SET B2C.dborderid = A.order_number__c
FROM b2csf B2C
JOIN Alemania A ON B2C.actualid = A.salesforce_id
I get this error:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '7201799-' to data type int.
I went ahead and changed it to:
UPDATE B2C
SET B2C.dborderid = (CASE
WHEN Isnumeric (a.order_number__c) = 1
THEN CAST(a.order_number__c AS INT)
END)
FROM b2csf B2C
JOIN Alemania A ON B2C.actualid = A.salesforce_id
And now I get
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '7575932.' to data type int.
My questions now are:
how can I avoid this error? I don’t mind for example losing '7575932.' value.(Ideally I would like to discard '7575932.' value)
I am trying my best to follow best practices... is changing the column DBorderid to nvarchar the only "best practice" alternative?
(I am using SQL Server 2008)
Instead of ... WHEN Isnumeric (a.order_number__c) = 1 ... use ... WHEN Isnumeric (a.order_number__c + '.0e0') = 1 ...
i have a form and onClick listener i want to update some data on my database exception says that i have a syntax error but when i execute query at mysql console it works here is my code all variables are checked
String temp = itemList.getModel().getElementAt(itemList.getSelectedIndex()).toString();
PreparedStatement pt = supplies.con.prepareStatement("update prods set pquant = pquant + ? where pname = ?");
pt.setInt(1, Integer.parseInt(empsalary.getText()));
pt.setString(2, temp);
supplies.pst.executeQuery(temp);
Error
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DVD Verdatim' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
at buy$1.actionPerformed(buy.java:62)
As the compiler mentioned, there is indeed a Syntax error in your SQL query. Try:
String temp = itemList.getModel().getElementAt(itemList.getSelectedIndex()).toString();
PreparedStatement pt = supplies.con.prepareStatement("update prods set pquant = #0 + 21" + "'variableForPquant'" "where pname = #1" + "'variableForPname'");
pt.setInt(1, Integer.parseInt(empsalary.getText()));
pt.setString(2, temp);
supplies.pst.executeQuery(temp);
You need to use quotes when you are using variables in your SQL query. I believe it is either
"'variableName'" or '"variableName'"
I found my error i declare a variable pt and i execute the query from the statement that is empty pst i change to pt.executeUpdate(); and its ok now
I am using MySQL with ASP.NET/VB. In a table I use GUID instead of int identifiers. All goes as planned until I try to update a specific row, where I get a syntax error in the statement below:
Dim q As String = "UPDATE documents SET date_document = #date_document, document_type = #document_type, sender = #sender, receiver = #receiver, description = #description, document_number = #document_number, pages = #pages, handled_date = current_timestamp, handled_user_id = #handled_user_id, error_code = #error_code) WHERE id = #id"
My GUID parameter:
.Parameters.Add("#id", MySqlDbType.Guid, 16).Value = myguid
And the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE id = '8873442f-2f0b-4372-ac08-8388220c6eca'' at line 1
Any ideas on what's going on?
You're chasing down the wrong issue. What character does your error syntax begin with? It starts off as ') Where id = ...
You're assuming it's the id. It's not. That works fine. The first character is a closing parenthesis. That's the clue. There is no opening parenthesis. Remove the ) because you don't need it with an update statement.