3 Replies Latest reply on Feb 8, 2005 10:16 AM by Max

    mysql-ds.xml setting

    Max Newbie

      Properties props = new Properties();
      props.setProperty("zeroDateTimeBehavior", "convertToNull");

      Instead of set the property in the program, how to set the connection properties in config file?

        • 1. Re: mysql-ds.xml setting
          Simon Godden Newbie

          I believe the element you want is <config-property>, e.g.

          <config-property name="zeroDateTimeBehaviour" type="java.lang.String">convertToNull</config-property>
          


          Making your entire ds.xml something like

          <datasources>
           <local-tx-datasource>
           <jndi-name>MySqlDS</jndi-name>
           <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
           <driver-class>com.mysql.jdbc.Driver</driver-class>
           <user-name>x</user-name>
           <password>y</password>
           <config-property name="zeroDateTimeBehaviour" type="java.lang.String">convertToNull</config-property>
           <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
           <!-- sql to call when connection is created
           <new-connection-sql>some arbitrary sql</new-connection-sql>
           -->
           <!-- sql to call on an existing pooled connection when it is obtained from pool
           <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
           -->
          
           <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
           <metadata>
           <type-mapping>mySQL</type-mapping>
           </metadata>
           </local-tx-datasource>
          </datasources>
          


          I've never had to do this, so I'm just guessing this will do what you need. Post to let people know if it succeeded.

          • 2. Re: mysql-ds.xml setting
            Max Newbie

            The correct spelling is zeroDateTimeBehavior

            <datasources>
             <local-tx-datasource>
             <jndi-name>MySqlDS</jndi-name>
             <connection-url>jdbc:mysql://localhost:3306/myApp</connection-url>
             <driver-class>com.mysql.jdbc.Driver</driver-class>
             <user-name>user</user-name>
             <password>password</password>
             <config-property name="zeroDateTimeBehavior" type="java.lang.String">convertToNull</config-property>
             <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
             <metadata>
             <type-mapping>mySQL</type-mapping>
             </metadata>
             </local-tx-datasource>
            
            </datasources>
            


            Anyway, there is still an error :
            SQLException : Value '0000-00-00' can not be represented as java.sql.Timestamp

            Anybody knows how to solve this problem? Thank you.

            • 3. Re: mysql-ds.xml setting
              Max Newbie

              Finally i solved the problem by using the other way.

              datasources>
               <local-tx-datasource>
               <jndi-name>MySqlDS</jndi-name>
               <connection-url>jdbc:mysql://localhost:3306/myApp?zeroDateTimeBehavior=convertToNull</connection-url>
               <driver-class>com.mysql.jdbc.Driver</driver-class>
               <user-name>user</user-name>
               <password>password</password>
               <metadata>
               <type-mapping>mySQL</type-mapping>
               </metadata>
               </local-tx-datasource>
              
              </datasources>