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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:43:46+00:00 2026-06-05T00:43:46+00:00

I have the following mysql query in PHP and it works fine. $strUpdate =

  • 0

I have the following mysql query in PHP and it works fine.

$strUpdate = "INSERT INTO  `batchfolder`.`newbatch` (`BatchID` ,`Batch` ,`barcode` ,`PG`)VALUES (NULL ,  '',  '1',  '')";

and is also fine when i run it directly in database.

However when I run it in java,

 try {
          conn = DriverManager.getConnection (url, userName, password);
          Statement st = conn.createStatement();
          st.execute("INSERT INTO  `batchfolder`.`newbatch` (`BatchID` ,`Batch` ,`barcode` ,`PG`)VALUES (NULL ,  '',  '1',  '')");            
          st.close();
}

It gives the following error.

Exception in thread "main" java.sql.SQLException: Field 'Pre' doesn't have a default value

Pre is the the next row in the database and it does not have a default value.

My question is, then how does this query run fine in mysql and php.

P.S BatchID is an int(10) autoincremented value in newbatch.

This is my table structure.

CREATE TABLE IF NOT EXISTS `newbatch` (
  `BatchID` int(10) NOT NULL AUTO_INCREMENT,
  `Batch` varchar(100) NOT NULL,
  `barcode` varchar(5) NOT NULL,
  `Ly` varchar(5) NOT NULL DEFAULT '0',
  `PG` varchar(5) NOT NULL,
  `Pre` varchar(5) NOT NULL,
  `Flu` varchar(5) NOT NULL,
  `FluID` varchar(100) DEFAULT NULL,
  `DateCreated` varchar(100) DEFAULT NULL,
  `Comments` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`BatchID`),
  UNIQUE KEY `FluID` (`FluID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1000160 ;
  • 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-05T00:43:47+00:00Added an answer on June 5, 2026 at 12:43 am

    Are you absolutely sure this actually runs in PHP? You may just not be seeing the error message.

    Try this again with display_errors = 'on' and error_reporting(E_ALL | E_STRICT);
    This is a SQL error, it doesn’t depend on the driver. The driver just displays the message to you.

    UPDATE:
    It looks like Java is turning off MySQL’s strict mode for some reason. The only thing that (to my knowledge) should be able to cause this behavior is MySQL strict mode being off.

    If strict mode is not enabled, MySQL sets the column to the implicit
    default value for the column data type.

    You can check the mode that your server is running on by SELECT @@GLOBAL.sql_mode;. Try that in both Java and PHP. If the results differ then that’s your answer.

    UPDATE2: Jep!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I execute the following in the MySQL console, it works fine: INSERT INTO
I have the following mysql query which I am running with php like so.
I have the following simple MySQL query, called from PHP: SELECT foo_id, SUM(number_of_guests) FROM
I have the following MySQL query that I execute from a .php page SELECT
I have the following PHP that creates some JSON from a MySQL query. This
I have the following mysql query. Could you please tell me how to write
I have the following mysql query, which is producing a list of entries by
I have the following MySQL-query: SELECT s.student_socialnr, s.student_lastname, s.student_firstname, cs.city_name, scp.cpl_startdate, scp.cpl_enddate, scp.cpl_invoice, cu.customer_name,
I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
I have the following mysql query: $manufacturers_query = select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, mi.manufacturers_url from

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.