Android Question How to convert SQL statements in B4A?

bskotu555

Member
'cx' and 'zw' are text variables:
strSQL ="SELECT * FROM smt where cxnm='" & cx & "' and zwnm='" & zw & "'"
Cursor = Starter.Mysql_Jdbc.ExecQuery(strSQL)
 

bskotu555

Member
Did you use backticks or single quotes? They're not the same character!
搜狗高速浏览器截图20241027190346.png

I put these two sentences into the program, but it just reported an error. What's the situation?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
View attachment 158030
I put these two sentences into the program, but it just reported an error. What's the situation?
If your column names are English word without blank spaces, then you don't need to escape them with back ticks.
Just write like this will do:
B4X:
Dim strSQL As String = "SELECT * FROM smt WHERE cxnm = ? AND zwnm = ?"
 
Upvote 0

walt61

Active Member
Licensed User
Longtime User
If your column names are English word without blank spaces, then you don't need to escape them with back ticks.
You are of course absolutely right. I make it a habit of using backticks for column and table names: then, I don't have to worry about them being reserved words or containing special characters.
 
Upvote 0
Top