Resultset.getDate() truncation

when i call getDate() from the resultset to receive the full date, . i get a truncated, date back, minus the time part.
i can use, getTimestamp() to retrieve the full date, . but then what is the easiest way to convert java.sql.timestamp to a normal date object for manip?

java.sql.timestamp is a thin wrapper around java.util.Date that allows JDBC to identify this as a SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP nanos value and provides formatting and parsing operations to support the JDBC escape syntax for timestamp values.
Note: This type is a composite of a java.util.Date and a separate nanos value. Only integral seconds are stored in the java.util.Date component. The fractional seconds - the nanos - are separate. The getTime method will return only integral seconds. If a time value that
includes the fractional seconds is desired, you must convert nanos to milliseconds
(nanos/1000000) and add this to the getTime value.
(above from Java Documentation)
I use:
java util.date dateField;
dateField=rset.getTimestamp("DATE_FIELD");
String s = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(dateField);
And the date and time are returned without using java.sql.timestamp. I don't need more than seconds precision.

Similar Messages

  • Assigning ResultSet.getDate()

    (Posted this query to Programming forum by mistake earlier, so copying it to this forum. Apologies, I'm a newbie here...)
    I am using ResultSet.getDate() to get a date field from MSSQL Server database. What variable type do I best assign the returned value to? getDate() returns a java.sql.Date object. I need to adjest date to account for time zone differences then return adjusted date to dbase.
    Have tried
    java.sql.Date cDate = rs.getDate("CDateTime");
    CDateTime is the name of the field in dbase, but I get an
    error thrown at this line as:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
    My select statement is:
    String sql = "SELECT * FROM \"CallRecd\"";
    ResultSet rs = stmt.executeQuery(sql);
    Would appreciate any comments on best way to assign rs.getDate().
    Any comments on why this error is thrown? I have double checked that column name used is correct.

    Hi tully4,
    What order are you trying to access your resultset fields? Apparently M$ SQL Server 7 doesn't like out of order access to resultset columns. If you access your resultset columns in ascending order everything is ok, but if you access a lower index column after a higher one.....
    BTW you should really specify each column you want to select rather than using SELECT *. You'll also know the order of your columns.
    Also, try using rs.getTimestamp(int colIndex, java.util.Calendar cal) instead of rs.getDate to get your date. You can use the calendar param to set the time zone (if you don't specify a time zone the default for your JVM is used).
    Richard

  • Bug in ResultSet#getDate() with ojdbc7-12.1.0.1

    As "documented" here java - ResultSet#getDate() semantics - Stack Overflow there seems to be a bug in ResultSet#getDate() with ojdbc7-12.1.0.1.
    The java.sql.Date condition
    To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero
    is violated.
    How can we report that to Oracle?

    Hello Hwang
    1/ I don't know for your first question. Have you checked all the RUEI rpm prerequisites? One should be missing probably.
    2/ One solutions consists of installing and configuring Squid proxy on the RUEI server. Then you can use your own browser with ruei server as a proxy and surf. You also need to tweak RUEI to collect traffic within the right network card.
    as $RUEI_USER :
    execsql config_set_profile_value wg profile_wg_localhost_1 config ForceInterface add eth0
    replace wg by the name of your profle (probably wg anyay) and eth0 by the proper network card (also eth0 probably).
    GL & HF
    JB

  • Why ResultSet getDate() method returns null when querying .csv file?

    Here is the full code:
    import java.sql.*;
    import java.sql.Types;
    import java.sql.Date;
    import myjava.support.CachedRowSetMaker;
    import javax.sql.rowset.CachedRowSet;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    class jdbc2{
    final private String s1="SELECT top 10 [DATE], [ADJ CLOSE] FROM [vwo-1.csv]";
    private ResultSet result=null;
    private Connection conn=null;
    public static void main(String[] args) throws SQLException{
    jdbc2 db=new jdbc2();
    try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              db.conn = DriverManager.getConnection("jdbc:odbc:STOCK_DATA");
              PreparedStatement sql=db.conn.prepareStatement(db.s1);
              db.result=sql.executeQuery();
    // check column names and types using the ResultSetMetaData object.
              ResultSetMetaData metaData = db.result.getMetaData();
         System.out.println("Table Name : " + metaData.getTableName(2));
         System.out.println("Field\t\tDataType");
         for (int i = 0; i < metaData.getColumnCount(); i++) {
         System.out.print(metaData.getColumnName(i + 1) + "\t");
         System.out.println(metaData.getColumnTypeName(i+1));
         System.out.print(metaData.getColumnName(1) + "\t"+metaData.getColumnName(2)+"\n");
              while (db.result.next()){
                   System.out.print(db.result.getDate("DATE", Calendar.getInstance()));
                   System.out.format("\t%,.2f\n", db.result.getFloat("Adj Close"));
    catch (Exception e) {
    System.out.println("Error: " + e.getMessage());
         finally {
              db.result.close();
              db.conn.close();
    Everything works well, until getting to the block
              while (db.result.next()){
                   System.out.print(db.result.getDate("DATE", Calendar.getInstance()));
                   System.out.format("\t%,.2f\n", db.result.getFloat("Adj Close"));
    The getDate("DATE", Calendar.getInstance())); always returns null, instead of the date value in the vwo-1.csv.
    Even though I change it to
    java.sql.Date d=db.result.getDate("DATE") and convert to String using .toString(), I still gets nulls. The dollar amount in "Adj Close" field is fine, no problem.
    The .csv fils is downloaded from YahooFinace.
    Can anyone review the code and shed some light as to what I did wrong?
    Thanks alot.

    CREATE TABLE `login` (
    `username` varchar(40) DEFAULT NULL,
    `password` varchar(40) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `amount` (
    `amountid` int(11) NOT NULL,
    `receiptid` int(11) DEFAULT NULL,
    `loanid` int(11) DEFAULT NULL,
    `amount` bigint(11) DEFAULT NULL,
    `latefee` int(11) DEFAULT NULL,
    `paymentid` int(11) DEFAULT NULL,
    `pid` int(11) DEFAULT NULL,
    PRIMARY KEY (`amountid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `applicationfee` (
    `applicationfeeid` int(11) DEFAULT NULL,
    `applicationamount` int(11) DEFAULT NULL,
    `applicationfee` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `category` (
    `categoryid` int(11) DEFAULT NULL,
    `categoryname` varchar(40) DEFAULT NULL,
    `categorydescription` varchar(500) DEFAULT NULL,
    `cattype` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `commission` (
    `commissionid` int(11) DEFAULT NULL,
    `bussiness` int(11) DEFAULT NULL,
    `commission` int(11) DEFAULT NULL,
    `pid` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `customer` (
    `cacno` int(11) NOT NULL DEFAULT '0',
    `name` varchar(40) DEFAULT NULL,
    `age` int(11) DEFAULT NULL,
    `cphone` varchar(40) DEFAULT NULL,
    `cmobile` varchar(40) DEFAULT NULL,
    `caddress` varchar(500) DEFAULT NULL,
    `cstatus` varchar(20) DEFAULT NULL,
    `cphoto` longblob,
    `pid` int(11) DEFAULT NULL,
    PRIMARY KEY (`cacno`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `daybook` (
    `closingbal` varchar(40) DEFAULT NULL,
    `date` date DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `extraincome` (
    `categoryid` int(11) NOT NULL,
    `receiptid` int(11) DEFAULT NULL,
    `date` date DEFAULT NULL,
    `amountid` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `employee` (
    `empno` int(11) DEFAULT NULL,
    `empname` varchar(40) DEFAULT NULL,
    `age` int(11) DEFAULT NULL,
    `sal` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `image` (
    `id` int(11) DEFAULT NULL,
    `image` blob
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `loan` (
    `loanid` int(11) NOT NULL DEFAULT '0',
    `loanamt` varchar(40) DEFAULT NULL,
    `payableamount` double DEFAULT NULL,
    `installment` int(11) DEFAULT NULL,
    `payableinstallments` int(11) DEFAULT NULL,
    `monthlyinstallment` varchar(20) DEFAULT NULL,
    `surityname` varchar(20) DEFAULT NULL,
    `applicationfeeid` int(11) DEFAULT NULL,
    `interestrate` float DEFAULT NULL,
    `issuedate` date DEFAULT NULL,
    `duedate` date DEFAULT NULL,
    `nextduedate` date DEFAULT NULL,
    `cacno` int(11) DEFAULT NULL,
    `cname` varchar(20) DEFAULT NULL,
    `pid` int(11) DEFAULT NULL,
    `interestamt` double DEFAULT NULL,
    `pendingamt` float DEFAULT NULL,
    PRIMARY KEY (`loanid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `md` (
    `mdid` int(11) NOT NULL DEFAULT '0',
    `mdname` varchar(40) DEFAULT NULL,
    `mdphoto` varchar(100) DEFAULT NULL,
    `mdphone` varchar(40) DEFAULT NULL,
    `mdmobile` varchar(40) DEFAULT NULL,
    `mdaddress` varchar(500) DEFAULT NULL,
    PRIMARY KEY (`mdid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `partner` (
    `pid` int(11) NOT NULL DEFAULT '0',
    `pname` varchar(40) DEFAULT NULL,
    `paddress` varchar(500) DEFAULT NULL,
    `pphoto` varchar(100) DEFAULT NULL,
    `pphone` varchar(40) DEFAULT NULL,
    `pmobile` varchar(40) DEFAULT NULL,
    `pstatus` varchar(20) DEFAULT NULL,
    `mdid` int(11) DEFAULT NULL,
    `mdname` varchar(40) DEFAULT NULL,
    `date` date DEFAULT NULL,
    `nextpaydate` date DEFAULT NULL,
    PRIMARY KEY (`pid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `partnerinvested` (
    `pid` int(11) DEFAULT NULL,
    `pname` varchar(20) DEFAULT NULL,
    `receiptid` int(11) DEFAULT NULL,
    `date` date DEFAULT NULL,
    `amountinvested` int(11) DEFAULT NULL,
    `latefee` int(11) DEFAULT NULL,
    `amountid` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `payments` (
    `paymentid` int(11) NOT NULL,
    `categoryid` int(11) DEFAULT NULL,
    `particulars` varchar(100) DEFAULT NULL,
    `amountid` int(11) DEFAULT NULL,
    `paymentdate` date DEFAULT NULL,
    PRIMARY KEY (`paymentid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    CREATE TABLE `receipts` (
    `receiptid` int(11) DEFAULT NULL,
    `paiddate` date DEFAULT NULL,
    `amountid` int(11) DEFAULT NULL,
    `loanid` int(11) DEFAULT NULL,
    `latefee` int(11) DEFAULT NULL,
    `installment` int(11) DEFAULT NULL,
    `cacno` int(11) DEFAULT NULL,
    `cname` varchar(40) DEFAULT NULL,
    `pid` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

  • About ResultSet.getDate

    when I insert the table ,I use the to_date function to insert the date value,such as to_date('2003-05-24 14:00:00','yyyy-mm-dd hh24;mi:ss')
    when using the Result.getDate,the return value of date is "2003-05-24",how can I get the correct value ?
    thks very much!!!!!!!!!!!!!!!

    try getTimestamp() instead.

  • Using getDate for ResultSet in jsp

    Hello,
    In a jsp I'm trying to display a date stored in a mysql database.
    In the jsp i have put the following:
    <TD align='right'>Meeting Date</TD>
    <TD align='right'>
    <INPUT type='text' name='meetingDate' value='<%= rsClients.getDate("meetingDate") %>'</TD>
    </TR>
    rsClients is the ResultSet where I have stored mysql table data.
    But when I run servlet that subsequently fires up jsp to display data stored in mysql database I get the following sql exception:
    java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
         at com.mysql.jdbc.ResultSet.getDateFromString(ResultSet.java:1913)
         at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1849)
         at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1817)
         at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1865)
         at org.apache.jsp.ProcessClients$jsp._jspService(ProcessClients$jsp.java:154)
    Can anyone explain why I'm getting this error please,
    Cheers Joe.

    I think you have store wrong data in Date Type field in MYsql
    so try to store data in formate of YYYY-MM-DD right now it is 0000-00-00
    Because you have try to enter any No,String or It isnot Correct date Type

  • ResultSets Closing, cant use .last() etc

    I am filling 3 seperate resultsets using 3 seperate sql queries.
    The 1st query calls the connection classes setData() and passes in the sql statement, which connects, gets the data, puts it in a resultset, and returns it to the calling class. Then, the returned resultset copied into resultset1.
    The 2nd query then does the same thing, but its sql statement is getting different data from a different table, but it still uses the getData() method to do it. It then fills resultset2.
    Then the 3rd query runs its sql query the same way to fill resultset3.
    The problem is, after i have filled resultsets 1, 2 and 3, it wont let me call a .first() or .last() on any of them cause it says that the resultset is closed! Heres the exact error msg:
    "java.sql.SQLException: Operation not allowed after ResultSet closed"
    Heres the code where i try fill the 3 resultsets:
              mycon = new MysqlConnect();
                   details_res = mycon.getData("SELECT * FROM details ORDER BY details_id");     
                   details_res.last();
                   parts_res = mycon.getData("SELECT * FROM parts ORDER BY parts_id");               
                   parts_res.last();
                   costs_res = mycon.getData("SELECT * FROM costs ORDER BY costs_id");
                   costs_res.last();'mycon' is an object of the connection class.
    So im guessing that ive got a problem in the getData() method of the connection class so heres the code for that method:
         public ResultSet getData(String query)
              connect();
              try
                   // browseable in all directions, not sensitive to updates by other users, not updateable
                   stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // create empty SQL statement
                   // execute SQL query & store results
                   result = stmt.executeQuery(query);
                   con.close();        // close connection
                   System.out.println("Data Retrieved. Connection Closed");
              catch (SQLException e)
                   System.out.println("SQL Exception " + e);
              return result; // return the data
         }//end getData()'stmt' and 'con' are both declared at the top, private variables.

    Right. Exactly. This is the way it's supposed to be. You've got major fundamental flaws in your approach.
    First, the result set is not being copied, you're creating a new reference to it.
    Second, result sets AREN'T copied.
    Third, a ResultSet represents an arbitrarily large flow of data that will come throw the connection as you step through elements in the ResultSet; as soon as you close the connection, you cut off the flow.
    So the excpetion is exactly right, you've closed the flow and therefore can't move around in the ResultSet.

  • Help: ResulSet.getDate(int col) rounds time to 12:00AM

    Using Microsoft SQL Server 7, I execute the following code:
    CREATE TABLE Test (RegDate DATETIME, SmallDate SMALLDATETIME)
    INSERT INTO Test (RegDate, SmallDate) VALUES ('1/1/2000 5:37 AM', '1/1/2000 5:37 AM')
    SELECT * FROM TestThis is the output that I get back:RegDate                     SmallDate                  
    2000-01-01 05:37:00.000     2000-01-01 05:37:00Ok, it looks good so far... now let me query this table with JDBC://just a snippet... I already have a connection, and a statement (stmt)
    SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy h:mm:ss a");
    ResultSet rs = stmt.executeQuery("SELECT * FROM Test");
    while(rs.next()) {
        System.out.println("RegDate is " + format.format(rs.getDate(1)));
        System.out.println("SmallDate is " + format.format(rs.getDate(2)));
    }The output from the java code is:RegDate is 1/1/2000 12:00 AM
    SmallDate is 1/1/2000 12:00 AMThe month, day and year are correct but the hours and minutes are 12:00 AM. How can I get the hours and minutes?
    Thanks,
    jay

    Okay, I did some reading and I learned that java.sql.Date will always show 12:00 AM (aka zero). There is a class called java.sql.Time which should take care of the time.
    I still don't know how to get the Date and time from a ResultSet though. I can call ResultSet.getDate(int col) or ResultSet.getTime(int col) but not both (after getting a column's value, subsequent calls return null). I even tried getting raw data and parsing it via ResultSet.getBytes() and ResutSet.getBinaryStream()... common sense tells me that there's got to be a cleaner, simpler way to do this. Surely I'm not the first person who wanted to read the date and time from a SQLServer DATETIME column!
    thanks again

  • A question about ResultSet

    Does anyone can tell me how to use ResultSet.getDate(String field, Calendar cal)method,, I have tried many way,,, but if I use this method, everytime throw a AbstractMethodError... thanks

    Calendar calendar = Calendar.getInstance();
    while(rs.next){
    rs.getDate("SYSDATE", calendar);
    and SYSDATE is a kind of DATE
    java.lang.AbstractMethodError occur while I run
    rs.getDate() Method ..
    is this a bug of java???It may simply be that the driver you are using doesn't support this method. Which driver and version are you using?
    Col

  • MsSQL 2000+Resultset.getString()

    Guys,
    I really need help for this issue. Here is the problem:
    - I am using Java 1.3.1/SE + EE
    - I have Ms SQL/2000
    This is the java code:
    Connection conn = null;
    String name;
    try
         conn = connectionPool.getConnection();
    Statement statement = conn.createStatement();
    ResultSet results = statement.executeQuery
    ("select * from USERAUTHENTICATION");
    while (results.next())
    name = results.getString("UserID");
    statement.close();
    finally
    if (conn != null)
    When java runs results.getString("UserID"), it gives this error:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
    It is weird because this code works under Oracle database.
    I will appreciate any help.
    PS. I am not expert a Java programmer. So if you have an answer, please give a little bit detail.
    Thank you
    Murat

    Thanks for the answer. I am sure that the column name and my text are exactly the same. The column is VARCHAR.
    Let me give more info:
    - One thing I noticed is that Resultset.getDate() works properly.
    - Resultset.getString() does not work for none of varchar type in SQL.
    I make the connection that way:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (Exception ignore) {}
    connectionPool = new MyConnectionPool(
    "jdbc:odbc:MYDATABASENAME", "sa", "");
    I am just wondering weather jdbc.odbc works properly or not.
    Thank you
    Murat

  • Get Date +time from Oracle

    hi ,
    i saw that i can take date and time in seperate from the ResultSet .
    how can i take the Time part as well from the date in the DB .
    is there a way to create a new Date with the Time from the DB concatinated to it ?
    doing as follows is apparently wrong ...
    Date taskStartDate = rs.getDate("start_assign");
                   Time taskStartTime = rs.getTime("start_assign");
                   long tt= taskStartTime.getTime();
                   Date taskStartDate = new Date(taskStartDatetmp.getTime()+tt);please advise .

    You could convertjava.sql.Date sqlDate = resultSet.getDate("foo");
    java.util.Date javaDate = new
    java.util.Date(sqlDate.getTime());
    This only works if the driver is ignorant enough to pass through millisecond values containing hours/minutes/seconds to the sql.Date, thus violating the contract of sql.Date.

  • Crystal report/SQL SP/DTSRUN

    Post Author: slk35psu
    CA Forum: Other
    Hi.
    &#91;Crystal Reports version 11.5.9.1076&#93;
    &#91;SQL Server 2000&#93;
    I have a SQL Server stored procedure that runs perfectly
    when I execute it in the database but it does not work in Crystal Report.
    The stored procedure executes two SQL scripts: drop table
    indexes and truncate tables.  After that,
    it calls a DTS package to transfer data from an Oracle database to the SQL
    database.  After the DTS package call, it
    executes two more SQL scripts to put back the table indexes and updates table
    statistics.  I can run the stored
    procedure in the SQL database (on both my computer and on its server).  The problem occurs when the stored procedure
    is called in the Crystal Report.  In
    Crystal Report, the stored procedure runs the drop table indexes and truncate
    tables scripts and the DTS package.  It
    seems to me that Crystal
    thinks the job is done at the completion of the DTS package and reports a
    success status.  It fails to continue to
    run the table indexes creation script and the table statistics update
    script.  What causes this?
    To summarize, the steps in the SQL database stored procedure
    are:
    Truncate
         tablesDrop
         indexesRun
         DTS package to transfer data from Oracle DB to SQL DBCreate
         indexesUpdate
         statistics
    The stored procedure works find when executed in the SQL database.  When executed in the Crystal Report, it stops
    (and thinks) it is done at the end of the DTS package run (step 3).
    I have pasted my stored procedure code below for your
    review.  Sincerely, Susan Kolonay.
    create proc dbo.WH_DATA_LOAD
    as
    SET NOCOUNT ON
    DECLARE @rc int
    DECLARE @WH_UNAME varchar(30)
    SET @WH_UNAME = 'whu1'
    DECLARE @WH_PWD varchar(30)
    SET @WH_PWD = 'K*e689f(k'
    DECLARE @WH_DB_SERVER_NAME varchar(30)
    SET @WH_DB_SERVER_NAME = 'ddasAA.psu.edu'
    DECLARE @SCRIPTS_LOC varchar(50)
    SET @SCRIPTS_LOC = 'E:\Scripts\cnv\TEST\'
    DECLARE @DTS_PKG_NAME varchar(30)
    SET @DTS_PKG_NAME = 'whse_build_routine'
    DECLARE @TRUNCATE_TBL varchar(200)
    DECLARE @DROP_INDEXES varchar(200)
    DECLARE @DTS_PKG varchar(200)
    DECLARE @CREATE_INDEXES varchar(200)
    DECLARE @UPDATE_TBL_STATS varchar(200)
    /CHECKING TABLE/
    if not exists (select 1 from sysobjects where type='U' and
    name='WH_DATA_LOAD_STATS' and uid=1)
    BEGIN
      PRINT
    'WH_DATA_LOAD_STATS does not exist.'
      RETURN
    END
    /TRUNCATE TEMPORARY TABLE/
    truncate table WH_DATA_LOAD_STATS
    /TRUNCATE TABLES/
    insert into WH_DATA_LOAD_STATS (time_started, process)
    values (getdate(), 'truncate table')
    SET @TRUNCATE_TBL = 'isql -U '@WH_UNAME' -P '@WH_PWD' -n
    -i '@SCRIPTS_LOC'trunc_whse_tables.sql 2>&1'
    EXEC @rc = master.dbo.xp_cmdshell @TRUNCATE_TBL
    IF @rc <> 0
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='failed' where
    process='truncate table'
    END
    ELSE
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='success' where
    process='truncate table'
    END
    /DROP INDEXES/
    insert into WH_DATA_LOAD_STATS (time_started, process)
    values (getdate(), 'drop indexes')
    SET @DROP_INDEXES = 'isql -U '@WH_UNAME' -P '@WH_PWD' -n
    -i '@SCRIPTS_LOC'drop_whse_indexes.sql 2>&1'
    EXEC @rc = master.dbo.xp_cmdshell @DROP_INDEXES
    IF @rc <> 0
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='failed' where
    process='drop indexes'
    END
    ELSE
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='success' where
    process='drop indexes'
    END
    /DTS PKG/
    insert into WH_DATA_LOAD_STATS (time_started, process)
    values (getdate(), 'DTS pkg')
    SET @DTS_PKG = 'dtsrun /S '@WH_DB_SERVER_NAME' /U sa /P
    abcdefg123 /N '@DTS_PKG_NAME' 2>&1'
    EXEC @rc = master.dbo.xp_cmdshell @DTS_PKG
    IF @rc <> 0
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='failed' where process='DTS
    pkg'
    END
    ELSE
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='success' where
    process='DTS pkg'
    END
    /CREATE INDEXES/
    insert into WH_DATA_LOAD_STATS (time_started, process)
    values (getdate(), 'create indexes')
    SET @CREATE_INDEXES = 'isql -U '@WH_UNAME' -P '@WH_PWD'
    -n -i '@SCRIPTS_LOC'create_whse_indexes.sql 2>&1'
    EXEC @rc = master.dbo.xp_cmdshell @CREATE_INDEXES
    IF @rc <> 0
    BEGIN
      update WH_DATA_LOAD_STATS
    set time_ended=getdate(), status='failed' where process='create indexes'
    END
    ELSE
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='success' where
    process='create indexes'
    END
    /UPDATE STATISTICS/
    insert into WH_DATA_LOAD_STATS (time_started, process)
    values (getdate(), 'update statistics')
    SET @UPDATE_TBL_STATS = 'isql -U '@WH_UNAME' -P
    '@WH_PWD' -n -i '@SCRIPTS_LOC'update_whse_stats.sql 2>&1'
    EXEC @rc = master.dbo.xp_cmdshell @UPDATE_TBL_STATS
    IF @rc <> 0
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='failed' where
    process='update statistics'
    END
    ELSE
    BEGIN
      update
    WH_DATA_LOAD_STATS set time_ended=getdate(), status='success' where
    process='update statistics'
    END
    /*select upper(process)'('status')'char(10)
    char(9)'Started on '+convert(varchar(8), time_started, 114)
                  +' ended
    on '+convert(varchar(8), time_ended, 114)
                  '   DURATION:'convert(varchar,datediff(mi,
    time_started, time_ended))+' minutes.'
          AS "REPORT"
    from WH_DATA_LOAD_STATS
    /*select process
         , status
    convert(varchar(8), time_started, 114) as "START_TIME"
    convert(varchar(8), time_ended, 114) as "END_TIME"
    convert(varchar,datediff(mi, time_started, time_ended)) as
    "DURATION_in_MIN"
    from WH_DATA_LOAD_STATS
    /*select '('status') 'upper(process)'Started on
    'convert(varchar(8), time_started, 114)' ended on '+convert(varchar(8),
    time_ended, 114)+' 
    DURATION:'convert(varchar,datediff(mi, time_started, time_ended))'
    minutes.' AS "REPORT"
    from WH_DATA_LOAD_STATS
    RETURN
    go

    Post Author: yangster
    CA Forum: Crystal Reports
    you are over thinking the problemsimply create a parameter within crystal for your state and change it to allow multiple valuesthen in the select expert put in state = ?stateif you do show sql query you will see that the values are pushed down to the sql level thus no performance hit vs putting the parameter directly in the command itself

  • How to retrieve records from a database and display it in a jsp page.Help!!

    Hello everyone ! im very new to this forum.Please help me to solve my problem
    First i ll explain what is my requirement or needed.
    Actually in my web page i have text box to enter start date and end date
    and one list box to select the month .If user select or enter the dates in text box
    accordingly the data from ms access database has to display in a jsp page.
    Im using jsp and beans.
    I tried returning ResultSet from bean but i get nothing display in my web page
    instead it goes to error page (ErrorPage.jsp) which i handle in the jsp.
    I tried many things but nothing work out please help me to attain a perfect
    solution. I tried with my bean individually to check whether the result set has
    values but i got NullPointerException . But the values which i passed or
    available in the database.
    I dint get any reply for my last post please reply atleast to this.
    i get the date in the jsp page is by this way
    int Year=Integer.parseInt(request.getParameter("year"));
    int Month=Integer.parseInt(request.getParameter("month"));
    int Day=Integer.parseInt(request.getParameter("day"));
    String startdate=Day+"/"+Month+"/"+Year;
    int Year1=Integer.parseInt(request.getParameter("year1"));
    int Month1=Integer.parseInt(request.getParameter("month1"));
    int Day1=Integer.parseInt(request.getParameter("day1"));
    String enddate=Day1+"/"+Month1+"/"+Year1;But this to check my bean whether it return any result!
    public void databaseConnection(String MTName,String startDate,String endDate)
    try
             java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
             java.util.Date fromDate=dateFormat.parse(startDate);
            java.util.Date tillDate=dateFormat.parse(endDate);          
            java.sql.Date sqlFromDate=new java.sql.Date(fromDate.getTime());
            java.sql.Date sqlTillDate=new java.sql.Date(tillDate.getTime());
              String query1="select MTName,Date,MTLineCount from Main where MTName='"+MTName+"'  and Date between '"+sqlFromDate+"' and '"+sqlTillDate+"' " ;
            System.out.println(query1);
              Class.forName(driver);
             DriverManager.getConnection(url);
             preparedStatement=connection.prepareStatement(query1);
             preparedStatement.setString(1,"MTName");
              preparedStatement.setDate(2,sqlFromDate);
              preparedStatement.setDate(3,sqlTillDate);
              resultSet=preparedStatement.executeQuery();           
               while(resultSet.next())
                        System.out.println(resultSet.getString(1));
                        System.out.println(resultSet.getDate(2));
                        System.out.println(resultSet.getInt(3));
            catch (Exception e)
             e.printStackTrace();
    I Passed value from my main method is like thisl
    databaseConnection("prasu","1/12/2005","31/12/2005");Please provide solutions or provide some sample codes!
    Help!
    Thanks in advance for replies

    Thanks for ur reply Mr.Rajasekhar
    I tried as u said,
    i tried without converting to sql date ,but still i din't get any results
    java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
             java.util.Date fromDate=dateFormat.parse(startDate);
            java.util.Date tillDate=dateFormat.parse(endDate);          
              String query1="select MTName,Date,MTLineCount from linecountdetails where mtname='"+MTName+"'  and Date >='"+fromDate+"' and Date <='"+tillDate+"' " ;
            System.out.println(query1);
    //From main method
    databaseConnection("prasu","1/12/2005","31/12/2005");I got the output as
    ---------- java ----------
    select MTName,Date,MTLineCount from linecountdetails where mtname='prasu'  and Date >='Thu Dec 01 00:00:00 GMT+05:30 2005' and Date <='Sat Dec 31 00:00:00 GMT+05:30 2005'
    java.lang.NullPointerException
    null
    null
    java.lang.NullPointerException
    Output completed (4 sec consumed) - Normal TerminationThanks
    Prasanna.B

  • Result set of One db to another DB

    Dear All,
    Need your help.
    I am posting my sample class below
    public static java.sql.ResultSet getData(String dbConnectStr,String dbuserID,String dbpwd,String query) throws Exception
    // Obtain default connection
    // Query all columns from the EMP table
    ResultSet rset = null;
    Connection conn = null;
    try
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@"+dbConnectStr,dbuserID,dbpwd);
    ((OracleConnection)conn).setCreateStatementAsRefCursor(true);
    stat.execute("alter session set NLS_DATE_FORMAT='DD-Mon-RRRR HH:MI:SS'");*/
    System.out.println(query);
    Statement stmt = conn.createStatement();
    rset = stmt.executeQuery(query);
    System.out.println("returning");
    catch (SQLException e)
    e.printStackTrace();
    // Return the ResultSet (as a REF CURSOR)
    return rset;
    ################################## My Function in Oracle DB
    FUNCTION DB_CALL(dbConnectStr VARCHAR2,dbuserID VARCHAR2,dbpwd VARCHAR2,query VARCHAR2) return axsbcstatement.CUR is language java name 'com.axs.logc.OracleDeployProcedure.getData(java.lang.String,java.lang.String,java.lang.String,java.lang.String) return java.sql.Resultset' ;
    ########################### My Procedure Where i am calling this function
    PROCEDURE INSERT_call (inward_dbConnectStr VARCHAR2,inward_dbuserID VARCHAR2,inward_dbpwd VARCHAR2,query VARCHAR2,updateCnt out number) as
    up_cnt number(6) :=0;
    db_cur axsbcstatement.inward_cur;
    ENTRY_NMBR_field dummy_table.Entry_Nmbr%type;
    SNDR_NAME_field dummy_table.Sndr_Name%type;
    SNDR_ADDRSS_field dummy_table.Sndr_Addrss%type;
    RCVR_NAME_field dummy_table.Rcvr_Name%type;
    REMARKS_field dummy_table.Remarks%type;
    TRAN_AMNT_field dummy_table.Tran_Amnt%type;
    TRAN_DATE_field dummy_table.Tran_Date%type;
    BATCH_TRANID_field dummy_table.Batch_Tranid%type;
    BATCH_TIME_field dummy_table.Batch_Time%type;
    BEGIN
    db_cur := INWARD_DB_CALL(inward_dbConnectStr,inward_dbuserID ,inward_dbpwd ,query);
    loop
    fetch db_cur into ENTRY_NMBR_field,TRAN_ID_field,SNDR_NAME_field,SNDR_ADDRSS_field,RCVR_NAME_field,REMARKS_field,TRAN_DATE_field,BNFCRY_field,BATCH_TRANID_field,BATCH_TIME_field;
    EXIT WHEN db_cur%NOTFOUND;
    begin
    select ENTRY_NMBR INTO ENTRY_NMBR_field from dummy_table where ENTRY_NMBR = entry_nmbr_field and TRAN_ID = TRAN_ID_field;
    if SQL%found then
    dbms_output.put_line('Data Found in table ');
    end if;
    Exception
    when no_data_found then
    insert into dummy_table values(ENTRY_NMBR_field,TRAN_ID_field,SNDR_NAME_field,SNDR_ADDRSS_field,RCVR_NAME_field,REMARKS_field,TRAN_DATE_field,BNFCRY_field,BATCH_TRANID_field,BATCH_TIME_field);
    up_cnt := up_cnt+1;
    end;
    end loop;
    close db_cur;
    updateCnt := up_cnt;
    Exception
    when others then
    dbms_output.put_line(' - ' || SQLCODE|| ' ' ||SQLERRM);
    END INSERT_call;
    I am getting "ORA-00932: inconsistent datatypes: expected a return value that is a java.sql.ResultSet got a java.sql.ResultSet that can not be used as a REF CURSOR" this error while executing the procedure...
    i have tried so many things but not able to solve this problem..
    Apart from this If someone suggest me ...........
    I am having two different database.with same table structure .
    i have to take data from db1 and insert into the db2 on incremental basis (some checks required while inserting into the db2)
    Regards .
    Salil

    Just modify your procedure like this
    CREATE OR REPLACE PROCEDURE insert_call (
       inward_dbconnectstr         VARCHAR2,
       inward_dbuserid             VARCHAR2,
       inward_dbpwd                VARCHAR2,
       QUERY                       VARCHAR2,
       updatecnt             OUT   NUMBER
    AS
       up_cnt               NUMBER (6)                      := 0;
       db_cur               axsbcstatement.inward_cur;
    --   entry_nmbr_field     dummy_table.entry_nmbr%TYPE;
    --   sndr_name_field      dummy_table.sndr_name%TYPE;
    --   sndr_addrss_field    dummy_table.sndr_addrss%TYPE;
    --   rcvr_name_field      dummy_table.rcvr_name%TYPE;
    --   remarks_field        dummy_table.remarks%TYPE;
    --   tran_amnt_field      dummy_table.tran_amnt%TYPE;
    --   tran_date_field      dummy_table.tran_date%TYPE;
    --   batch_tranid_field   dummy_table.batch_tranid%TYPE;
    --   batch_time_field     dummy_table.batch_time%TYPE;
       all_rec              dummy_table.%ROWTYPE;
    BEGIN
       db_cur := inward_db_call (inward_dbconnectstr, inward_dbuserid, inward_dbpwd, QUERY);
       LOOP
          FETCH db_cur
           INTO all_rec;
          EXIT WHEN db_cur%NOTFOUND;
          BEGIN
             SELECT entry_nmbr
               INTO entry_nmbr_field
               FROM dummy_table
              WHERE entry_nmbr = all_rec.entry_nmbr AND tran_id = all_rec.tran_id;
             IF SQL%FOUND
             THEN
                DBMS_OUTPUT.put_line ('Data Found in table ');
             END IF;
          EXCEPTION
             WHEN NO_DATA_FOUND
             THEN
                INSERT INTO dummy_table
                     VALUES (all_rec.entry_nmbr, all_rec.tran_id, all_rec.sndr_name, all_rec.sndr_addrss, all_rec.rcvr_name, all_rec.remarks, all_rec.tran_date,
                             all_rec.bnfcry, all_rec.batch_tranid, all_rec.batch_time);
                up_cnt := up_cnt + 1;
          END;
       END LOOP;
       CLOSE db_cur;
       updatecnt := up_cnt;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (' - ' || SQLCODE || ' ' || SQLERRM);
    END insert_call;Regards,
    Mahesh Kaila

  • Oracle Java Call

    Dear All,
    Need your help.
    I am posting my sample class below
    public static java.sql.ResultSet getData(String dbConnectStr,String dbuserID,String dbpwd,String query) throws Exception
    // Obtain default connection
    // Query all columns from the EMP table
    ResultSet rset = null;
    Connection conn = null;
    try
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@"+dbConnectStr,dbuserID,dbpwd);
    ((OracleConnection)conn).setCreateStatementAsRefCursor(true);
    stat.execute("alter session set NLS_DATE_FORMAT='DD-Mon-RRRR HH:MI:SS'");*/
    System.out.println(query);
    Statement stmt = conn.createStatement();
    rset = stmt.executeQuery(query);
    System.out.println("returning");
    catch (SQLException e)
    e.printStackTrace();
    // Return the ResultSet (as a REF CURSOR)
    return rset;
    ################################## My Function in Oracle DB
    FUNCTION DB_CALL(dbConnectStr VARCHAR2,dbuserID VARCHAR2,dbpwd VARCHAR2,query VARCHAR2) return axsbcstatement.CUR is language java name 'com.axs.logc.OracleDeployProcedure.getData(java.lang.String,java.lang.String,java.lang.String,java.lang.String) return java.sql.Resultset' ;
    ########################### My Procedure Where i am calling this function
    PROCEDURE INSERT_call (inward_dbConnectStr VARCHAR2,inward_dbuserID VARCHAR2,inward_dbpwd VARCHAR2,query VARCHAR2,updateCnt out number) as
    up_cnt number(6) :=0;
    db_cur axsbcstatement.inward_cur;
    ENTRY_NMBR_field dummy_table.Entry_Nmbr%type;
    SNDR_NAME_field dummy_table.Sndr_Name%type;
    SNDR_ADDRSS_field dummy_table.Sndr_Addrss%type;
    RCVR_NAME_field dummy_table.Rcvr_Name%type;
    REMARKS_field dummy_table.Remarks%type;
    TRAN_AMNT_field dummy_table.Tran_Amnt%type;
    TRAN_DATE_field dummy_table.Tran_Date%type;
    BATCH_TRANID_field dummy_table.Batch_Tranid%type;
    BATCH_TIME_field dummy_table.Batch_Time%type;
    BEGIN
    db_cur := INWARD_DB_CALL(inward_dbConnectStr,inward_dbuserID ,inward_dbpwd ,query);
    loop
    fetch db_cur into ENTRY_NMBR_field,TRAN_ID_field,SNDR_NAME_field,SNDR_ADDRSS_field,RCVR_NAME_field,REMARKS_field,TRAN_DATE_field,BNFCRY_field,BATCH_TRANID_field,BATCH_TIME_field;
    EXIT WHEN db_cur%NOTFOUND;
    begin
    select ENTRY_NMBR INTO ENTRY_NMBR_field from dummy_table where ENTRY_NMBR = entry_nmbr_field and TRAN_ID = TRAN_ID_field;
    if SQL%found then
    dbms_output.put_line('Data Found in table ');
    end if;
    Exception
    when no_data_found then
    insert into dummy_table values(ENTRY_NMBR_field,TRAN_ID_field,SNDR_NAME_field,SNDR_ADDRSS_field,RCVR_NAME_field,REMARKS_field,TRAN_DATE_field,BNFCRY_field,BATCH_TRANID_field,BATCH_TIME_field);
    up_cnt := up_cnt+1;
    end;
    end loop;
    close db_cur;
    updateCnt := up_cnt;
    Exception
    when others then
    dbms_output.put_line(' - ' || SQLCODE|| ' ' ||SQLERRM);
    END INSERT_call;
    I am getting "ORA-00932: inconsistent datatypes: expected a return value that is a java.sql.ResultSet got a java.sql.ResultSet that can not be used as a REF CURSOR" this error while executing the procedure...
    i have tried so many things but not able to solve this problem..
    <b><h3>
    Apart from this If someone suggest me ...........
    I am having two different database.with same table structure .
    i have to take data from db1 and insert into the db2 on incremental basis (some checks required while inserting into the db2)
    ..</h3>
    </b>
    Regards .
    Salil

    Oracle JMS client libraries work only with Oracle AQ/JMS. These will not work with MQ series.
    You might have to load MQ series JMS client libraries.
    null

Maybe you are looking for

  • Login JSP losing Session

    I have a Login JSP which talks to a Servlet which then passes the login request to a Bean. In the Bean I save the login information in the Session, if the login fails I am trying to 'forward' to the Login JSP page again. On the Login JSP there is an

  • Oracle BI Java host not starting for Windows 7 64 bit

    Hi, I am struggling to start "Oracle BI Java host" on my Windows 7 64 bit machine. All other services - BI Server, Presentation Server and even OC4J works good. BI Version: OBIEE 10g EE - 10.1.3.4.1 I have checked these places: 1. Environment variabl

  • I have been having multiple issues lately with my iMac

    I have been having multiple issues lately with my iMac - starting with insanely slow processing/run speeds.  When I run Activity Monitor, consistently the highest usage of CPU is "ReportCrash" - typically shows up as 80-200% of CPU. What could this b

  • Can i Customize the Discoverer Reports

    Hello, I mean to say that like we make a report in Report Builder and can write text on the report. So can we write any thing on the report in discoverer? Regards Mustafa Ali Qizilbash

  • Background scrolls, how to stop it?

    Hi I am currently using and css is .bg {     width: 100%;     height: 95%;     position: absolute;     top: 0;     left: 0;     z-index: -5000;  But on smaller screens i have noticed that the background scrolls with content. Is there a simple fix to