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

Similar Messages

  • 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

  • How we can assign resultset variable to javascript variable

    can any1 plsss
    i want to assign resultset variable to javascript variable but it diagnosis some mesg like that
    type can not resolved"
    my code as follows
    <%! ResultSet al=(ResultSet)request.getAttribute("mydata");%>
    <script language="JavaScript">
    <%--<% ResultSet al = (ResultSet)request.getAttribute("mydata");%>--%>
    var alm=<%=al%>
    function pass()
    while(alm.next())
    document.write(document.myApp.dataValidation(alm.getString("Login")));
    document.write(document.myApp.dataValidation(alm.getString("Passwd")));
    document.write("<br>");
    </script>
    <jsp:plugin type="applet" code="TestApp.class"
    name="myApp"
    codebase="http://localhost:8080/dbServlet/"
    width="600"
    height="80">
    </jsp:plugin>
    <input type="button" value="Click me!"
    onclick="pass()" >

    double post http://forum.java.sun.com/thread.jspa?threadID=5245891&tstart=0

  • Error  while assigning resultset value to Querytable variable in Coldfusion 10

    We are upgrading from coldfusion 8 to 10. Internally we were using java function to to get the data.
    In java function we have a resultset object, if we assign this resultset value to Querytable variable, we are getting below error. This code was working fine in coldfusion 8.
    Detail    This exception is usually caused by service startup failure. Check your server configuration.
    Message    The Runtime service is not available.
    StackTrace    coldfusion.server.ServiceFactory$ServiceNotAvailableException: The Runtime service is not available. at coldfusion.server.ServiceFactory.getRuntimeService(ServiceFactory.java:117) at coldfusion.runtime.RequestMonitor.<clinit>(RequestMonitor.java:14) at coldfusion.sql.QueryTable.populate(QueryTable.java:358) at coldfusion.sql.QueryTable.populate(QueryTable.java:283) at coldfusion.sql.QueryTable.<init>(QueryTable.java:96) at com.myCompany.myClass.myFunct(myClass.java:627) at
    Here is the function which is causing error.
    static private QueryTable myFunct(String userId, SessionFactory sf) {
            PreparedStatement pStmt = null;
            ResultSet rs = null;
            QueryTable ret = null;
             try{
                Query q = sf.getCurrentSession().getNamedQuery("ListUsers");
                pStmt = sf.getCurrentSession().connection().prepareStatement(q.getQueryString());
                rs = pStmt.executeQuery();// works fine till here
                ret = new QueryTable(rs);  // error line         
                rs.close();
            }catch(Exception e){
                e.printStackTrace();
                throw new RuntimeException(e.getLocalizedMessage());
            return ret;
    Can you provide some help on this. Please let me know if you need any other details.

    We have found this error is logs
    coldfusion.runtime.Encryptor$InvalidParamsForEncryptionException: An error occurred while trying to encrypt or decrypt your input string: The input and output encodings are not same..
        at coldfusion.runtime.Encryptor.decrypt(Encryptor.java:303)
        at coldfusion.runtime.Encryptor.decrypt(Encryptor.java:284)
        at coldfusion.runtime.CFPage.Decrypt(CFPage.java:5353)
        at coldfusion.runtime.CFPage.Decrypt(CFPage.java:5326)
        at coldfusion.runtime.CFPage.Decrypt(CFPage.java:5458)
        at com.vmware.vcp.service.impl.EncryptColdFusionImpl.decrypt(EncryptColdFusionImpl.java:65)
        at com.vmware.vcp.web.servlet.ApplicationConfigServlet.initEmailService(ApplicationConfigSer vlet.java:119)
        at com.vmware.vcp.web.servlet.ApplicationConfigServlet.init(ApplicationConfigServlet.java:51 )
        at javax.servlet.GenericServlet.init(GenericServlet.java:160)
        at coldfusion.bootstrap.ClassloaderHelper.initServletClass(ClassloaderHelper.java:121)
        at coldfusion.bootstrap.BootstrapServlet.init(BootstrapServlet.java:59)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5001)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5278)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)

  • 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;

  • 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.

  • 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.

  • 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

Maybe you are looking for

  • Windows 8 Add a Device not finding all of my IP printers

    Hello all.  My organization is migrating to Windows 8. We currently use IP printers in our offices (24 locations total). Currently, in XP, we have a customized powershell script that allows users to locate a printer and install it.  In windows 8, we'

  • Why is there a 4450 error message coming up and i can't burn cds???

    I will try to burn a playlist to disk, but when i start to burn a CD, it stops in the middle and says something about a 4450 error. I've been through several blank CDs and have tried to fix it by doing all the steps iTunes recommended, but nothing's

  • Outlook 2010 - Data File Properties/Folder Size verses Windows Explorer pst file size

    I am running Outlook 2010 32bit Version 14.0.6129.5000 on a Windows PC running Windows 7 Professional.  All updates from MS are up to date. I have several pst files I open with Outlook 2010. The size of the files displayed in Outlook are very differe

  • Bad bind variable 'NEW

    Hi, I'm trying to run a script to generate the table. And I'm getting the following error at create or replace trigger bi_wvufr_applications before insert on wvufr_applications for each row begin if :new.application_id is null then select wvufr_appli

  • Error in solution manager

    Hi basis gurus. I am installing solution manager 4.0 sr4. os is windows 2003 standard edition. database db2 ver9.1. At installation,  Starting the instance phase i got error.. Dynamic link library(DLL) initiliazation routine failed. error in db6conne