Date and null problem

Hello Techies,
I am using mysql 5.0 and trying to inserting couple of values in to a table called books.
CREATE TABLE books(
    book_id   INT AUTO_INCREMENT PRIMARY KEY,
    author_id INT,
    title     VARCHAR(255),
    pub_date  DATE);when i insert null values in the pub_date thru jdbc,I am getting the following exception.
SQLExceptionIncorrect date value: 'null' for column 'pub_date' at row 1But when tried from command prompt with the following query, values are inserted into the database.
INSERT INTO books VALUES(2, 2, "java", null);Here is my code.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class databaseTest {
     public static void main(String args[])
          Connection conn = null;
             ArrayList  col = new ArrayList();
          //Collection  col = new ArrayList();
          try
          //DBBackupPM dd = new DBBackupPM();
            conn = getConnection();
               col.add("1");
               col.add("1");
               col.add("java");
               col.add("null");
          String query = "INSERT INTO books VALUES(?,?, ?, ?);";
          PreparedStatement ps = conn.prepareStatement(query);
          int j=0;
          for(int i =0;i<col.size();i++)
               j++;
               System.out.println(col.get(i).toString());
               ps.setString(j,col.get(i).toString());
          ps.executeUpdate();
          System.out.println("Query Xcuted");
          catch (SQLException sqe) {
               // TODO: handle exception
               System.out.println("SQLException"+sqe.getMessage());
          System.out.println("collection size"+col.size());
          Iterator it = col.iterator();
          while(it.hasNext())
               System.out.println("yyuy"+it.next());
     public static  Connection getConnection() {
          System.out.println("inside GetConnection()");
          Connection conn = null;
          try {
               String driverName = "org.gjt.mm.mysql.Driver";
               Class.forName(driverName);
               String serverName = "localhost";
               String mydatabase = "test";
               String url = "jdbc:mysql://" + serverName + "/" + mydatabase +"?autoReconnect=true";
               String username = "root";
               String password = "xxx";
               conn = DriverManager.getConnection(url, username, password);
               System.out.println("connection established");
          } catch (ClassNotFoundException cnfe) {
               // Could not find the database driver
               System.out.println("classNotFoundExcpetion" + cnfe.getMessage());
          } catch (SQLException sqe) {
               // Could not connect to the database
               System.out.println("SQLException" + sqe.getMessage());
          return conn;
}can u guys tell me why I am getting the xception .
regards,
krish

public class databaseTest {
     public static void main(String args[])
          Connection conn = null;
             ArrayList  col = new ArrayList();
          //Collection  col = new ArrayList();
          try
          //DBBackupPM dd = new DBBackupPM();
            conn = getConnection();
               col.add("1");
               col.add("1");
               col.add("java");
               col.add("null");You are not inserting a null value here. You are trying to insert the text "null" as the value for the pub_date field. That won't work because the string "null" is not a valid date. What you're actually doing is this:
INSERT INTO books VALUES(2, 2, "java", "null");Note the quotes around "null".
You should set the column to the value null, not to the string "null".

Similar Messages

  • Null Date and Time Problem

    I created my entity classes from a database by using netbeans 6.0 and I'm using H2 as a database. I've the following table in my database.
    CREATE CACHED TABLE OPEN_TABLE ( ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY, TABLE_ID INTEGER, WAITER_ID INTEGER, OPEN_HOUR TIME DEFAULT CURRENT_TIME, OPEN_DATE DATE DEFAULT CURRENT_DATE );
    and here is the entity class netbeans created for me.
    import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; /** * * @author Yupp */ @Entity @Table(name = "OPEN_TABLE") @NamedQueries({@NamedQuery(name = "OpenTable.findById", query = "SELECT o FROM OpenTable o WHERE o.id = :id"), @NamedQuery(name = "OpenTable.findByTableId", query = "SELECT o FROM OpenTable o WHERE o.tableId = :tableId"), @NamedQuery(name = "OpenTable.findByWaiterId", query = "SELECT o FROM OpenTable o WHERE o.waiterId = :waiterId"), @NamedQuery(name = "OpenTable.findByOpenHour", query = "SELECT o FROM OpenTable o WHERE o.openHour = :openHour"), @NamedQuery(name = "OpenTable.findByOpenDate", query = "SELECT o FROM OpenTable o WHERE o.openDate = :openDate")}) public class OpenTable implements Serializable {     private static final long serialVersionUID = 1L;     @Id     @Column(name = "ID", nullable = false)     private Integer id;     @Column(name = "TABLE_ID")     private Integer tableId;     @Column(name = "WAITER_ID")     private Integer waiterId;     @Column(name = "OPEN_HOUR")     @Temporal(TemporalType.TIME)     private Date openHour;     @Column(name = "OPEN_DATE")     @Temporal(TemporalType.DATE)     private Date openDate;     public OpenTable() {     }     public OpenTable(Integer id) {         this.id = id;     }     public OpenTable(Integer id, Date openHour, Date openDate) {         this.id = id;         this.openHour = openHour;         this.openDate = openDate;     }     public Integer getId() {         return id;     }     public void setId(Integer id) {         this.id = id;     }     public Integer getTableId() {         return tableId;     }     public void setTableId(Integer tableId) {         this.tableId = tableId;     }     public Integer getWaiterId() {         return waiterId;     }     public void setWaiterId(Integer waiterId) {         this.waiterId = waiterId;     }     public Date getOpenHour() {         return openHour;     }     public void setOpenHour(Date openHour) {         this.openHour = openHour;     }     public Date getOpenDate() {         return openDate;     }     public void setOpenDate(Date openDate) {         this.openDate = openDate;     }     @Override     public int hashCode() {         int hash = 0;         hash += (id != null ? id.hashCode() : 0);         return hash;     }     @Override     public boolean equals(Object object) {         // TODO: Warning - this method won't work in the case the id fields are not set         if (!(object instanceof OpenTable)) {             return false;         }         OpenTable other = (OpenTable) object;         if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {             return false;         }         return true;     }     @Override     public String toString() {         return "OpenTable[id=" + id + "]";     } }
    The problem is when I try to insert a new OpenTable to the database, Open_Date and Open_Hour columns stay as null. I want them to get the automatic CURRENT_DATE and CURRENT_TIME values. I can't see where the problem is because I used CURRENT_DATE and CURRENT_TIME words when I created the table. I don't have any problems when I use standart SQL statements to insert a new row. I just use INSERT INTO OPEN_TABLE(TABLE_ID, WAITER_ID) VALUES(2,3) and get current date and hour values automatically but JPA doesn't do that for me. What should I do to solve the problem?

    Those database defaults are only applied when you use an INSERT statement that specifies a list of columns excluding the ones with defaults. Presumably your persistence code always sets all columns when it does an INSERT, so the defaults won't apply. You'll have to find the way to set the defaults in the persistence layer, not in the database.

  • DATE and TIMESTAMP problem - fixable with 11.1 JDBC Driver?

    I'm adding some queries to an older part of our code base and while reading through the documentation for one of the classes I found that we weren't using our normal Hibernate queries because we needed to ensure that we weren't sending Timestamps to Oracle. Apparently the Timestamp would be converted to a Date because the column in the database was of type DATE. This was causing problems because the DATE column's index was being ignored and the table contains millions of records.
    The Oracle FAQ seems to indicate that this has been fixed in the 11.1 JDBC drivers. I know that I can use 11.1 JDBC drivers with a 10.2.0 database, but will it use the new 11.1 mappings for DATE and TIMESTAMP or the old 10.2.0 mappings? Oracle FAQ page: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01

    Oracle FAQ page: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01
    Well obviously that was really stupid.
    I'm adding some queries to an older part of our code base and while reading through the documentation for one of the classes I found that we weren't using our normal Hibernate queries because we needed to ensure that we weren't sending Timestamps to Oracle. Apparently the Timestamp would be converted to a Date because the column in the database was of type DATE. This was causing problems because the DATE column's index was being ignored and the table contains millions of records.
    Not sure I follow that logic.
    If the value was going into the database then it would update the index.
    From that only one of the following could be true.
    1. It wasn't going into the database.
    2. It was being truncated to a date.
    The Oracle FAQ seems to indicate that this has been fixed in the 11.1 JDBC drivers. I know that I can use 11.1 JDBC drivers with a 10.2.0 database, but will it use the new 11.1 mappings for DATE and TIMESTAMP or the old 10.2.0 mappings? I would agree with your interpretation of the FAQ.
    And I would then follow it up by testing both with the old driver and the new.

  • Time, date and settings problems with boot camp

    I have recently installed Windows XP using boot camp on my macbook, and everything seemed to be working fine for a while. However, after a couple of weeks, i am now getting date and time errors every time i shut down Windows and boot back into Mac OS. Upon restart the date always resets it self to December 2000, and this causes multiple programs to stop working. Also, airport forgets my wireless settings and no longer connects to my base station until i re-enter the passwords, so the date wont correct itself using the internet. The only way i have been able to set the correct time and date is to either set it manually, or to use the ethernet cable as it requires no passwords, which is inconvenient as my base station is in a awkward place.
    After resetting the time, date and internet settings, my macbook works perfectly again until the next time i use boot camp. I have also had exactly the same problem with another macbook i have, and cannot figure out how to stop this from happening.

    FAT32 will accessible from both Windows and OS X
    If you don't want to reformat your ext drive you need something like http://www.paragon-software.com/home/hfs-windows/ or http://www.mediafour.com/products/macdrive/

  • Date and time problems

    On my older imacG5 running tiger I am able to display the clock as a floating transparent icon on the desktop which shows the date and time,
    on my newer intel imac and macbook pro running leopard I cannot do this, in fact there's two things that I can't do with leopard;
    1. I can't get the date displayed in the menu bar even when clicking show date and time in menu bar (only shows day of the week and time, but not the date)
    2. I can't get any clock to be displayed on the desktop? it's either in the menu bar or not at all.
    am I missing something or has Apple taken this feature away?
    (surely this isn't progress??)
    What's different in the two OS's is this:
    In Tiger date and time System Prefs there is a View In "Window" or "Menu Bar" option
    (selecting Window put s the clock on the desktop)
    as well as a sliding transperancy button which makes the clock see thro
    neither of these options are available in Leopard, so!!
    Is there a way to import the clock from the older machine/OSX?
    cheers

    Forgot to add when the time changes on its own, the time zone also changes to New York. I originaly set it to Montreal.

  • Quality and WorkForce Management ACD data and some problems

    I installed the Quality / Adv Quality Mgt. and than i installed workforce management services. I have access panels each service no problem. But, I constantly getting the following mail from WFO and I do not know how to solve
    WFM2001
    Message:
    The Capture Service is failing to capture ACD data.
    Action: Contact technical support.
    Other problem; I can't see anything about my agents, teams or etc. when i open WFO web management page or Quality Manager Administration.
    For example on WFO web management page, left pane, Agents menu, i can't see my CXX agents.
    Last one, i need to WFO and Qualit Management Recording using documentation (how to use both programs ?)
    Thx....

    Hi
    Documentation is here : http://www.cisco.com/en/US/products/ps8293/tsd_products_support_series_home.html
    It would appear you haven't set up the SQL connection as directed in chapter 3 of the install guide.
    Aaron

  • Enter Date and Time Problems

    When the entering the date or time in application like contacts birthday  etc...  the date button icons are all on top of each other and pressing the icon only brings up the year field.  The time is the same issue, all time button icons are on top of each other and only the am/pm field can be entered.   Got any suggestions?
    Post relates to: Pixi p120eww (Sprint)

    Hello K_Johanson and welcome to the Palm forums.
    I'm running webOS 1.4.5 on my Sprint Pre and I'm not seeing this issue when I try to enter a date for a birthday in Contacts.
    Have you tried restarting your phone?  Do you have the problem if you create a new Contacts record?
    Alan G

  • PI 7.3 - AEX "unable to read configuration data" and login problems

    Hello Friends,
    after installation of AEX, i'm facing some problems.
    1.I'm not able to login with any user, i created during installation wizard. So i cannot check any user in NWA -> User Administration.
    2.Once more, while opening http://<host>:<port>/rep or http://<host>:<port>/dir, i get the following error message.
    Can somebody help me?
    I think, there is a problem with the users, which have been created during installation. How can i check this? Is there any chance?
    Second, if i'm able to login, i have to import the exchange profile again. This should solve the problem. Or is this wrong?
    PI (http://<host>:<port>/dir/start/index.jsp). Below is the part of the error message that is showing up. Appreciate your suggestions:
    Exception class: com.sap.aii.utilxi.prop.api.PropertiesException$InitFailed
    Message
    Unable to read configuration data (ExchangeProfile/aii.properties)
    Stacktrace
    Thrown:
    com.sap.aii.utilxi.prop.api.PropertiesException$InitFailed: Unable to read configuration data (ExchangeProfile/aii.properties)
    at com.sap.aii.utilxi.prop.api.PropertySourceFactory.initServerMode(PropertySourceFactory.java:220)
    at com.sap.aii.utilxi.prop.api.AIIProperties.initServerMode(AIIProperties.java:518)
    at com.sap.aii.ib.server.applcomp.StartupServerProperties.initPropertiesForServer(StartupServerProperties.java:97)
    at com.sap.aii.ibdir.server.applcomp.StartupCodeEntry.startup(StartupCodeEntry.java:151)
    at com.sap.aii.ib.core.applcomp.IStartupCodeEntry.startupIfNotAlreadyDone(IStartupCodeEntry.java:43)
    at com.sap.aii.ib.core.applcomp.ExplicitApplicationComponentImpl.startup(ExplicitApplicationComponentImpl.java:116)
    at com.sap.aii.ib.core.applcomp.ExplicitApplicationComponents.startup(ExplicitApplicationComponents.java:438)
    at com.sap.aii.ib.core.applcomp.ApplicationComponent.startup(ApplicationComponent.java:203)
    Please let me know if I am not clear.
    Edited by: Clarence on Feb 6, 2012 3:28 PM
    Edited by: Clarence on Feb 6, 2012 3:28 PM

    hi,
    >>>>Second, if i'm able to login, i have to import the exchange profile again. This should solve the problem. Or is this wrong?
    if you have java stack only there is no exchange profile anymore...
    https://weblogs.sdn.sap.com/pub/wlg/28334
    Regards,
    Michal Krawczyk

  • Cellular Data and Wifi Problem

    Hi Guys.  I wonder if you can advise?
    I have an iPhone 4S on a monthly contract with an unlimited cellular data plan.  The phone is set to Settings-General-Cellular-On= Cellular Data On, Enable 3G On, Data Roaming On.  Also, Settings-Wi-Fi On-Ask To Join Networks.
    My phone finds and connects to my home network when I come back to the house but when I'm out it will not connect to any other Wifi network.  I have tried all of the resets and stuff but no good.  When I try to connect to a new network the Login page comes up but no details and then the remote server times out.  If I go to Safari and try to access a web page I just get the pop up asking me to join a Wifi Network and when I do an error popup shows saying that the network is unavailable.
    Messing around with the phone I have found that if I turn off Cellular Data (web, 3G, email push using wifi only) I can access other networks but, of course, have no 3G cellular data service unless I am in a wifi hotspot.
    Is there a way to make the phone switch to cellular data on 3G when out of range of wifi and back again?
    Anyway, if anyone can advise it would be appreciated.
    Regards
    Paul

    UPDATE:
    Turning off Cellular Data at a local wifi spot (not used before) didn't work this time.  However, turning off Cellular and going into Settings-General-Reset-Reset Network Settings then acquiring the wifi network did. I could then turn Cellular Data back on and use the wifi spot.
    Will try at another hotspot soon to see if the phone will automatically ask to join the network and allow me to do so without doing the above, as I don't want to be re-inputting other network passwords etc over and over again.

  • Date and varchar2 problem

    hi there
    when trying to make a procedure inserting into DATE or VARCHAR2 columns it results an error
    the used syntax is:
    create or replace procedure add_asset (table_name varchar2,consdate date)
    is
    begin
    execute immediate 'INSERT INTO ' || table_name || ',CONSTRUCTION_DATE) values (155,'|| consdate ||')';
    end;
    the execution line:
    exec add_asset('PUMP','12-MAR-02');
    results the error:
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "ADIS.ADD_ASSET", line 4
    ORA-06512: at line 1
    any help?
    again that error results also when i want to insert into a VARCHAR2 column.

    SQL> create table emp1 (empno number,hiredate date)
      2  /
    Table created.
    SQL> create or replace procedure add_asset (table_name varchar2,consdate date)
      2  is
      3  begin
      4  DBMS_OUTPUT.PUT_LINE('INSERT INTO ' || table_name || '(empno,hiredate) values (155,'||''''||consdate||''''||')');
      5  execute immediate 'INSERT INTO ' || table_name || '(empno,hiredate) values (155,'||''''||consdate||''''||')';
      6  end;
      7  /
    Procedure created.
    SQL>  exec add_asset('EMP1','12-MAR-02');
    INSERT INTO EMP1(empno,hiredate) values (155,'12-MAR-02')
    SQL> SELECT * FROM emp1
      2  /
        EMPNO HIREDATE
          155 12-MAR-02Khurram

  • Date and Timezone problem...

    Hello,
    Please, can sombody explain me the following program
              long l = System.currentTimeMillis();
              for (int i = 0; i < 25; i++ ){
                   l = l - 86400000;
                   System.out.println(i+":"+new Date(l));
    Output:
    0:Tue Apr 23 09:26:15 CEST 2002
    1:Mon Apr 22 09:26:15 CEST 2002
    2:Sun Apr 21 09:26:15 CEST 2002
    3:Sat Apr 20 09:26:15 CEST 2002
    4:Fri Apr 19 09:26:15 CEST 2002
    5:Thu Apr 18 09:26:15 CEST 2002
    6:Wed Apr 17 09:26:15 CEST 2002
    7:Tue Apr 16 09:26:15 CEST 2002
    8:Mon Apr 15 09:26:15 CEST 2002
    9:Sun Apr 14 09:26:15 CEST 2002
    10:Sat Apr 13 09:26:15 CEST 2002
    11:Fri Apr 12 09:26:15 CEST 2002
    12:Thu Apr 11 09:26:15 CEST 2002
    13:Wed Apr 10 09:26:15 CEST 2002
    14:Tue Apr 09 09:26:15 CEST 2002
    15:Mon Apr 08 09:26:15 CEST 2002
    16:Sun Apr 07 09:26:15 CEST 2002
    17:Sat Apr 06 09:26:15 CEST 2002
    18:Fri Apr 05 09:26:15 CEST 2002
    19:Thu Apr 04 09:26:15 CEST 2002
    20:Wed Apr 03 09:26:15 CEST 2002
    21:Tue Apr 02 09:26:15 CEST 2002
    22:Mon Apr 01 09:26:15 CEST 2002
    23:Sun Mar 31 09:26:15 CEST 2002
    24:Sat Mar 30 08:26:15 CET 2002
    Why does does the Timezone change?
    CEST => CET????
    Any Ideas
    Greeting & Thanks
    Peter

    CEST means Central European Summer Time.
    CET means Central European Time.
    Is has something to do with the summer time.

  • How to differentiate the EMPTY Records and Null Values in DSO

    Hello....how is everyone here?? Ehehehe!
    I try to load some data from the flat file which contains some EMPTY data and Null Values for the records. The data type for the InfoObjects of the fields "Quantity" is "number". The sample data from the flat file (CSV) are as below:
    Food              Quantity
    Hamburger  -       12
    Cheese        -       0
    Vegetable      -               (Empty)
    When I try to load the above sample data to the DSO, I get the results of the data as follow:
    Food              Quantity
    Hamburger     - 12.000
    Cheese           -  0.000
    Vegetable         - 0.000
    In this case, how can the user differentiate whether the records is contain empty value of null values in DSO? This is kinda of hard to differentiate the both scenarios above. Is there any way to differentiate the scenarios described here?
    Thanks alot =)

    Hi Fluffy,
    It depends on the initial values of the data type
    The inital values For quantity/Currency/ Numbers it takes spaces as 0
    for char it is SPACE
    We cannot differeniate between space and null values.
    IF you have to force this then define quantity as char and load the data. we will not have units and aggregation in this case.
    Hope this helps.
    PV

  • Multiple Plug-in and crashing problems

    Fairly recently, I have been getting plug in error messages that freeze my browser up for minutes at a time. This happens on multiple websites. I have tried to update my add-ons, but I am having issues even updating those. For example, I am running on adobe acrobat 10.1.1.33 and my browser tells me it is out of date. I click to update, and it takes me to a page that says the plug in has been blocked. It will not allow me to update through that avenue. I click the general 'check to see if your plug ins are up to date,' but on that page, I am told that the plug in IS up to date. I have tried manually installing the different updates I need (as this is happening with several different plug ins) but the update is apparently not applying. I have also done a general firefox 'reset' and am completely up to date. I just want the freezing and constant error messages to go away.

    Crashes or other problems with certain multimedia content in Firefox (such as Youtube videos and Flash animations or games) can often be resolved by performing the steps in these Knowledge Base articles:
    * [[Flash Plugin - Keep it up to date and troubleshoot problems]]
    * [[Flash 11.3 crashes]]
    * [[Flash 11.3 doesn't load video in Firefox]]
    On Windows Vista and above, you can disable Flash protected mode by following the instructions on these pages:
    * http://forums.adobe.com/thread/1018071#TemporaryWorkaround
    * http://kb.mozillazine.org/Flash#Disabling_Protected_Mode_in_Flash_11.3
    (See [http://blogs.adobe.com/asset/2012/06/inside-flash-player-protected-mode-for-firefox.html this Adobe blog post] for technical details about Flash protected mode.)
    Please tell us if this helped!

  • Spotify and facebook problem with the date

    Hi, everyone.My spotify account have a problem with the date. I changed the date on facebook and nothing happens with that, the spotify account has a wrong date, is not the same as facebook account

    Hi ,
    By default , RFC accept date format of SQL date (yyyy-mm-dd) . If you are using a date picker from WD, it directly set the date in SQL date format. Incase if you are trying to pass date to RFC in some other way you have to convert that into SQL date format before passing.
    if you are passing String date of format dd-mm-yyyy , you try this method to convert that to SQL date and pass to your RFC.
    public java.sql.Date sqlDateConvert( String date)  {
        //@@begin sqlDateConvert()
         java.sql.Date dateObj=null;
         try{     
              StringTokenizer tempStringTokenizer = new StringTokenizer(""+date,"-");          int dd=Integer.parseInt(tempStringTokenizer.nextToken().trim());
                                    int mm=Integer.parseInt(tempStringTokenizer.nextToken().trim());
              mm=mm-1;
              int yyyy=Integer.parseInt(tempStringTokenizer.nextToken().trim());
              Calendar cal =Calendar.getInstance();   
              cal.set(yyyy,mm,dd);                         
              dateObj = new java.sql.Date( cal.getTime().getTime());
         }catch(Exception e)
              return dateObj;
    Hope this will help you.

  • Problem with date and time preference

    hi there,
    i set my date and time and the time support yesterday and then i click the lock button to prevent further chance and last night i shut down my iMac, open it again in the morning the lock open back up and the timezone support change.
    i redo that again and restart my iMac the same thing happen. is this a problem with my software or everyone have this problem?
    any idea what should i do?
    thanks in advance
    regards AL

    Having the same problem, & am running Parallels (which I haven't used for some time) not boot camp. I tick the box labeled "Set time automatically" & lock the "click the lock to make changes". When I reboot, the Lock is unlocked and the "set time...." is unticked. Any ideas. Cheers.

Maybe you are looking for