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 5969835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:17:15+00:00 2026-05-22T20:17:15+00:00

Hi i am trying to execute query Statement stmt = conn.createStatement(); stmt.executeUpdate(location_query); location_query is

  • 0

Hi i am trying to execute query

Statement stmt = conn.createStatement();
stmt.executeUpdate(location_query);

location_query is

insert into table(col, col2) value("2", "");

Both col and col2 are double(12,2) type, i get error
Data truncated for column 'col2' at row 1, but if I print my query and copy, and paste it to PMA (PhpMyAdmin) its correct.

I guesst that its becouse value of col2 is empty, but is there chance to solve this in other way not to checking all variables which im trying to put to my query ??

  • 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-05-22T20:17:16+00:00Added an answer on May 22, 2026 at 8:17 pm

    Well, an empty String is not a valid number, therefore different database systems might handle that differently. When you just want that column NULL or filled with the default, you should leave it out like this:

    insert into table(col) value(2);
    

    OR set it NULL explicitly:

    insert into table(col, col2) value(2, NULL);
    

    Besides, numbers are written without quotes in SQL. Furthermore, you should cosider using PreparedStatements only. PreparedStatements give you type saftly and protect from SQL injection and might be faster when reused.

    Take a look at google “statement vs. preparedstatement”

    EDIT

    Your example would look something like this, when using prepared statements:

    String yourFirstString = "2.34";
    String yourSecondString = "";
    
    double yourFirstDouble = 0;
    double yourSecondDouble = 0;
    
    if(yourFirstString  != null && yourFirstString.trim().length() > 0){
      try {
         yourFirstDouble = Double.parseDouble(yourFirstString); 
      }catch(NumberFormatException e){
        // handle Exception here
      }
    }
    
    // same parsing for the second double
    
    PreparedStatement stmt = conn.prepareStatement("insert into table (col, col2) value(?, ?)");
    stmt.setDouble(1, yourFirstDouble);
    stmt.setDouble(2, yourSecondDouble);
    stmt.executeUpdate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute a basic INSERT statement on a MySQL table from a
I'm trying to execute a query but I get an error: Unknown table alias
I am trying to execute a query on a table in my SQL Server
I'm trying to use a BULK INSERT statement to populate a large (17-million-row) table
I'm trying to execute the following CFML: <cfquery name=koppelData datasource=#request.DataSource#> INSERT INTO t_user_profile (Username,
I am trying to execute this SQL query prior to restoring a .BAK file
I am trying to execute the following query. update share set holder = 22
this is my first question. I'm trying to execute a SQL query in django
I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException:
I trying execute next FQL query SELECT uid FROM user WHERE name='Vovka' and getting

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.