Hi,

I do some tests on the database Oracle, Postgres and InstantDB.
(I haven't a Sybase database).
All works fine on Oracle and Postgres.
I got some problems on InstantDB with fields which are java.sql.Time.
Problem is not due to JOnAS; indeed, it is bring to the force in a
simple java program which use only the java.sql package.
You can so do some simple java.sql tests on Sybase to help you
to understand your problem.
I send you the simple java program I used to do java.sql test
on Oracle, PostGres and InstantDB.

I hope it helps you.
Kind regards.
Hélène.

Ritesh wrote:
> 
> Hi
> 
>     I am using jonas2.1.2 .
>     I am having sybase and entity beans (CMP) in which some filds are datetime .
>     I have 3 different text boxes for yy/mm/dd and then i am mkaing object of 
>Timestamp
>     and passing it to the datetime field to insert.
>     It not giving any problem but in database it is not going properly
>     It takes any value .
> 
>     I was fighting with this problem throught out the day but
>     I am unable to figure out what is the problem
> 
> Thanks
> Ritesh

-- 
-=- Hélène JOANIN -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  mailto:[EMAIL PROTECTED]   http://www.evidian.com
  Phone: 33.4.76.29.73.53            Fax: 33.4.76.29.76.00
  Download our EJB Server JOnAS at http://www.objectweb.org

import java.sql.*;

public class TstJDBCDate {

    public static void main(String[] arg) {

        try {

            // init Postgres
            Class drvClass=Class.forName ("postgresql.Driver");
            String url  = "jdbc:postgresql:db_jonas";
            String user = "jonas";
            String passwd = "jonas";
            // init Oracle
            //Class drvClass=Class.forName ("oracle.jdbc.driver.OracleDriver");
            //String url  = "jdbc:oracle:thin:@acores:1521:OTS";
            //String user = "demo1";
            //String passwd = "oode";
            // init InstantDB
            //Class drvClass=Class.forName ("org.enhydra.instantdb.jdbc.idbDriver");
            //String url  = "jdbc:idb=/server/products/idb/3.25/joanin/db/db.prp";
            //String user = "";
            //String passwd = "";

            System.out.println("-- URL="+url);

            Connection conn = DriverManager.getConnection(url, user, passwd);
            Statement stmt = conn.createStatement();
            PreparedStatement pStmt = null;
            long currenttime = System.currentTimeMillis();
            Date d = new Date(currenttime);
            Time t = new Time(currenttime);
            Timestamp ts = new Timestamp(currenttime);
            String pk = new String("FIRST");
            String tableName = new String("TBTestDate");

            // drop
            try {
                stmt.execute("drop table "+tableName);
                System.out.println("-- drop table");
            } catch (Exception e) {
                System.out.println("Exception in dropTable IGNORED : "+e);
            }

            // create table
            stmt = conn.createStatement();
            // create table for Oracle
            //stmt.execute("create table "+tableName+" (PKField varchar(6) primary 
key, DateField Date, TimeField Date, TimestampField Date)");
            // create table for PostGres and InstantDB
            stmt.execute("create table "+tableName+" (PKField varchar(6) primary key, 
DateField Date, TimeField Time, TimestampField Timestamp)");
            System.out.println("-- create table");

            // insert a row
            pStmt = conn.prepareStatement("insert into "+tableName+" (PKField, 
DateField, TimeField, TimestampField) values (?, ?, ?, ?)");
            pStmt.setString(1, pk);
            if (d == null) {
                pStmt.setNull(2, Types.DATE);
            } else {
                pStmt.setDate(2, d);
            }
            if (t == null) {
                pStmt.setNull(3, Types.TIME);
            } else {
                pStmt.setTime(3, t);
            }
            if (ts == null) {
                pStmt.setNull(4, Types.TIMESTAMP);
            } else {
                pStmt.setTimestamp(4, ts);
            }
            pStmt.executeUpdate();
            System.out.println("-- insert into (d="+d+",t="+t+",ts="+ts+")");

            // select the row
            pStmt = conn.prepareStatement("select PKField, DateField, TimeField, 
TimestampField from "+tableName+" where PKField=?");
            pStmt.setString(1, pk);
            ResultSet rs = pStmt.executeQuery();
            if (rs.next() == false) {
                System.out.println("ERROR: Cannot select the row");
                System.exit(2);
            }
            d = rs.getDate("DateField");
            t = rs.getTime("TimeField");
            ts = rs.getTimestamp("TimestampField");
            System.out.println("-- select result (d="+d+",t="+t+",ts="+ts+")");

            // close
            stmt.close();
            System.out.println("-- stmt close");
            pStmt.close();
            System.out.println("-- pStmt close");
            conn.close();
            System.out.println("-- conn close");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Reply via email to