Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT VisitorName, HostName, DateVisit, VisitType FROM pvmsvisitor WHERE Log...' at line 1


What I have tried:

and my query is this
<pre>"INSERT INTO visitorslog(VisitorName, HostName, DateVisit, VisitType, TimeIn, TimeOut)VALUES (?,?,?,?,?,?) SELECT VisitorName, HostName, DateVisit, VisitType FROM pvmsvisitor WHERE LogID = 1";

I'm using mysql database and java langauge
Posted
Updated 29-Dec-21 4:50am
Comments
Richard MacCutchan 29-Dec-21 10:25am    
Your INSERT clause requires six items but your SELECT clause returns only four.

1 solution

I would suggest to change your SQL to
INSERT INTO visitorslog
(VisitorName, HostName, DateVisit, VisitType, TimeIn, TimeOut)
  SELECT VisitorName, HostName, DateVisit, VisitType, TimeIn, TimeOut 
  FROM pvmsvisitor WHERE LogID = 1"

Like Richard mentioned in his comment there are two missing fields and additional the VALUES are not needed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900