Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:47:50+00:00 2026-06-12T13:47:50+00:00

I get an syntax error while trying to INSERT some values to Mysql from

  • 0

I get an syntax error while trying to INSERT some values to Mysql from Java.

My code looks like this:

date = new SimpleDateFormat("yyyy-MM-dd").parse(nextLine[0]);
        java.sql.Timestamp sqlDate = new java.sql.Timestamp(date.getTime());
        st.executeUpdate("INSERT INTO " + tick + "(day, open, high, low, close, volume) VALUES (" + sqlDate + ", " + nextLine[1] + ", " + nextLine[2] + ", " + nextLine[3] + ", " + nextLine[4] + ", " + nextLine[5] + ")"); 

My exception:

com.mysql.jdbc.exceptions.jdbc4.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 ’00:00:00.0,
128.40, 128.50, 127.30, 128.20, 1415200)’ at line 1

Would be glad for any help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:47:52+00:00Added an answer on June 12, 2026 at 1:47 pm

    While it would be possible to just fix the immediate syntax error, I would strongly recommend against it. You shouldn’t be including the values directly in your SQL at all.

    Instead, use a parameterized query via PreparedStatement, and set your values into the parameters instead. In this case, you’d use PreparedStatement.setTimestamp to set the value – after changing the query to be parameterized in the first place, of course.

    Benefits of parameterized SQL:

    • Prevention of SQL injection attacks
    • Avoidance of error-prone string conversions (as witnessed in this case)
    • Separation of code and data, leading to SQL which is simpler to read
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get data from the link from this code and get
Here's an ASPX code snippet from when I was trying to get multiple values
Why do i get the following error Incorrect syntax near 'AUTO_INCREMENT'. while trying to
I'm receiving the following error with this page while trying to retrieve information from
I get a syntax error in Python 2.7.3 like so: [s += 'Orig' for
Why do I get a syntax error from print "Hello World" in Python 3.2?
I can't figure out why I get this error: Parse error: syntax error, unexpected
See also SO 1664677 I get this error 2: Syntax error: ( unexpected when
Why do I always get the following error from Postgres? syntax error at or
I get this error when I run the application Incorrect syntax near 12 ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.