Problem in Resultset

hello
i got a problem using jfreechart. as the constructor of the chart takes and integer and double[], but how can we pass resultset into double[]. i tried converting the resultset into double and store it in a vector. reading the size of vector and copying that into a double array. i suceed. but when i pass that doubleArray[i] into jfreechart its saying cannot convert. in otherway its giving hexa decimal values.

Okay, let's walk through this..
You've got your ResultSet, which you loop through and put everything into an ArrayList or Vector, or whatever. Once you've done that, create a double array of ArrayList.size, and put the values from the list into the double array. Now your values from your database are in a double[] format which you can pass to chart.setSampleValues(). No need for a second double array anywhere in there.
As far as your code though, don't put the code to create the double[] inside your while(rs.next()) loop. After that loop has finished, then find out the size of the ArrayList and create the double array.

Similar Messages

  • Problem with ResultSet in a loop

    hi,
    i have a probleme with ResultSet when, my code is bellow
    ResultSet rs = stmt.executeQuery(sql);
    sql="SELECT NAME FROM prestationtemp";
    rs = stmt.executeQuery(sql);
    String sqlDel="";
    while (rs.next())
    sqlDel="Delete from prestation where NAME="+rs.getString("NAME");
    stmt.executeQuery(sqlDel);
    the problem is that the loop iterate just once like if there is just one record, and if I remove stmt.executeQuery(sqlDel); from the loop it iterate normaly.
    thanks in advance.

    you will need to use 2 Statments e.g.
    Statement stmt1 = connection.createStatement();
    Statement stmt2 = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    sql="SELECT NAME FROM prestationtemp";
    rs = stmt1.executeQuery(sql);
    String sqlDel="";
    while (rs.next())
    sqlDel="Delete from prestation where NAME="+rs.getString("NAME");
    stmt2.executeQuery(sqlDel);
    } When you reuse a Statement, any resultsets previously created are automatically closed.
    Looking at your code, it seems that you only need 1 SQL call:
    Delete from prestation where NAME in (SELECT NAME FROM prestationtemp)
    Much more efficient!

  • Urgent: Character Set Problem with ResultSet

    When I use normal statement as below the program works well:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String URL = "jdbc:oracle:thin:@10.1.20.8:1521:ora92";
    Properties prop = new Properties();
    prop.setProperty("user","unistock");
    prop.setProperty("password","unistock");
    Connection myconn = DriverManager.getConnection(URL, prop);
    if (myconn == null) {/ to do:.... }
    // in the table, the name, address are defined
    // as varchar2(20), and are in the format of
    // Chinese characters.
    String sql = "select name, address from tbl_node";
    Statement mystmt = myconn.createStatement(sql);
    ResultSet myresult = mystmt.executeQuery(sql); ......
    In such way, I can get the String object of NAME and ADDRESS, which are all Chinese character string.
    But when I produce the ResultSet objects that are scrollable in below way it fails to get original string:
    //.... the same as before
    Statement mystmt = myconn.createStatement(sql,
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet myresult = mystmt.executeQuery(sql); ......
    What I get from such way are strings which lost the highest bit information and I can't 'translate' they to the original ones, because maybe they are mixed with Chinese characters and English characters.
    What happens when I create the scrollable Statement object? And how can I fix such problem?

    hi manidhar,
    I am also facing the same problem.In my case the characters are getting garbled when it is passed to a javaScript function.
    Did u find a solution.
    If yes please post it.
    thanks in advance

  • Problems passing Resultset to SubReport

    Hello Everybody,
    I have a very simple Problem but I can not fix it. I have a Report which contains a Subreport. The Subreport is nearly the same like the Mainreport, I´m also passing Parameters to the Subreport. This works fine.
    But if I try to pass a ResultSet, the ReportViewer ask for Username an Password of the Database. The Subreport contains further all Datasets of the Database and not the custombuild in the Mainapplication.
    Does anybody know why this happend?
    Thanks a lot.
    Markus

    Please define "Fails". Error? Behavior? Symptom?
    - Ludek

  • Problem in resultSet if there was nothing retrieved

    im making a query on a certain number and if the resultSet was empty ...how can i tell if its empty or not ??!
    for example im looking for a student whose number is 123 and didnt find the student ...how can i do that ??
    i tried resultSet.wasNull() but didnt work ...any suggestions ?? thanks ..

    Didnt work ....heres a sample of my code :
    if( resultSet == null )
    javax.swing.JOptionPane.showMessageDialog(null,"Student was not found","No Data Found",javax.swing.JOptionPane.ERROR_MESSAGE);
    else
    while (resultSet.next() )
    for( int i=1;i<=numberOfColumns;i++ )
    newRow[i-1] = resultSet.getObject(i);
    model.addRow(newRow);
    jTable1.changeSelection(row, 0, false, false);
    row++;
    please anyone help me ...

  • Problems with ResultSet

    I'm working with Application Server WebLogic 5.1.
    In my Servlet or JSP why can't I invoke the ResultSet methods getRow, afterLast, beforeFirst
    when the method next works?
    My error message is:
    Servlet failed with Exception java.lang.AbstractMethodError

    those methods can only be used with a "scrollable" ResultSet. If your ResultSet was not created as a scrollable resultset, these methods can't be used. Another reason could be that your driver does not support the scrollable resultset. Post the statement/resultset code so that we can give you more accurate advice.
    Jamie

  • Problem of resultset

    how can i use resultset to display data from first row to last row of my database on the screen... can resultset do looping... and how to write looping for resultset??thanks
    ResultSet rs=stmt.executeQuery("select * from notice");
    rs.next();
    tf1.setText(rs.getString(1));
    tf2.setText(rs.getString(2));
    tf3.setText(rs.getString(3));
    tf4.setText(rs.getString(4));
    ta5.setText(rs.getString(5));

    the code to use loop is,
    ResultSet rs=stmt.executeQuery("select * from notice");
    while(rs.next()) {
    tf1.setText(rs.getString(1));
    tf2.setText(rs.getString(2));
    tf3.setText(rs.getString(3));
    tf4.setText(rs.getString(4));
    ta5.setText(rs.getString(5));
    if u don't know how many colums are there then u need to use Metadata.

  • Problems with ResultSet.first()

    hi,
    i think, i can�t reset the pointer of a resultSet to the fist element. why?
    code:
    ResultSet rs ....
    while (rs.next()) // this is ok!!!
    //a bit later:
    rs.first()
    while ( rs.next() ) // does nothing...
    thanx for any help
    jules

    the cursor is not positioned in the same place before the two loops begin.
    ResultSet rs ....
    while (rs.next()) // this is ok!!!
    //a bit later:
    rs.first()
    while ( rs.next() ) // does nothing...
    { ... }if you have 4 rows of data then the first row you would get rows 1,2,3 and 4 in the second loop you would get 2,3 and 4 because first put you on row 1 and the first call to next puts you on row 2.
    you should do this instead...
    while(rs.next()){
    // do something
    rs.beforeFirst();
    while(rs.next()){
      // do something else
    }now those loops are the same.

  • Problem with resultset FetchSize() method

    I am making call to stored procedure.I have set the fetchsize of result set to 1000.Even though the size is set for first fetch only 10 records are fectched which is default size and for next fetch 1000 records are returned.
    I am using Tomcat web server and oci driver.
    Can anyone pls help me i need all 1000 records in first fetch

    I am making call to stored procedure.I have set the
    fetchsize of result set to 1000.Even though the size
    is set for first fetch only 10 records are fectched
    which is default size and for next fetch 1000 records
    are returned.
    I am using Tomcat web server and oci driver.
    Can anyone pls help me i need all 1000 records in
    first fetchI believe that fetchSize is a suggestion to the jdbc driver, not a command. On some drivers it is ignored, on others it helps. It might help to know:
    How do you know that 10 and then 1000 rows are returned?
    What is the reason for your requirement of 1000 rows on the first call?

  • Problem with resultset.next inside 817 DB

    I have a java class running inside 817 database.
    I have a prepared statement that gets some records and loops through them and writes a record into another table.
    The SQL statement should produce 3000 records but only 566 get logged in the loop.
    I have looked at/tried everything. NOTHING seems wrong but jus tI dont get alll the records. The datatset is not truncated, records are missing ramdomly throught, ie recs 1-4 are OK then 5,6,7 are missing etc..
    Anyone know what the prb might be, its really weird and driving me nuts
    Rob
    null

    thank you for the pointers.
    For the RS is empty I've done a check with
    if(selectRs.next()!=null), even though
    next() is never suppose to be null, Yeah, you needn't bother with that. It's never supposed to be null, and if it is, there's a bug in the executeQuery method.
    ?so that confuses
    me. I've also put Sys.outs before & after the if
    statement & found it never prints out the System.out
    after the if(rs.next()). & I've stepped
    through with my WAS Debugger as a last restort to see
    what's going on. :$ So you're saying you put a print statement as the first statement right inside if (rs.next()) and it didn't get executed?
    I did do as you suggested with the
    count(*) & it did return a count of 1.You did that in your Java code? Changing only what you're selecting from those couple of columns to count(*), leaving the from and where alone?
    I am catching the SQLException for the try but
    nothing for the
    a_ruleSyntax.equals(current_ruleSyntax).Not sure what you're saying here, and not sure what your catch block looks like.
    I have put a System.out for if the equals returns
    false.
    Do you have any other ideas?Nope, sorry.
    If your answers to my questions above are "yes, that's what I'm doing," then I'm out of ideas, unless there's some exception that you're smothering.

  • Problem with ResultSet

    Hi all,
    i m giving select query n after that rs = prepareStmt.executeQuery();
    after that i gave one sout to chk the flow it is coming after that statement properly.and after that i gave :---
    while (rs.next())
    sout("test");
    but it didn't print. if i run that query separately it is giving 6 records.
    Can u plz suggest what would be the reason behind it???
    Thanks n Regards,
    Sneha

    In a web application (JSP) use a data source instead of DriverManager.
    Re: Database connection in Simple JSP

  • ResultSet from Java Stored Procedures

    Hi,
    How do I obtain a resultset from a Java Stored Procedure?
    My stored procedure, deployed in Oracle8i, has Database package as sample.Have published setConnection() and getDept() methods.
    Code for Java Stored Procedure:
    package SPPackage;
    import java.sql.*;
    public class StoredProcApplication {
    protected static Connection connection = null;
    protected static Statement stmt = null;
    protected static ResultSet res = null;
    public static void setConnection() throws SQLException {
    connection = new oracle.jdbc.driver.OracleDriver().defaultConnection();
    public static void getDept(Object[] obj) throws SQLException {
    if (connection == null) {
    setConnection();
    if (stmt == null) {
    stmt = connection.createStatement();
    if (res == null) {
    res = stmt.executeQuery("select * from DEPT");
    obj[0] = res;
    Code for TesterApplication :
    package SPPackage;
    import java.sql.*;
    public class TesterApplication {
    private static final String URL = "jdbc:oracle:thin:@sandeep:1521:oracle8i";
    private static final String userId = "sandeep";
    private static final String password = "sandeep";
    private Connection connection;
    private CallableStatement stmt;
    private ResultSet res;
    public void setConnection() throws ClassNotFoundException,SQLException {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection = DriverManager.getConnection(URL,userId,password);
    public void getResultFromSP() throws SQLException {
    //prepare to call the stored procedure
    stmt = connection.prepareCall("{call sample.getDept(?)}");
    //register the OUT parameters
    stmt.registerOutParameter(1,Types.OTHER);
    //execute the query
    stmt.execute();
    ResultSet res = (ResultSet)stmt.getObject(1);
    while (res.next()) {
    System.out.print(res.getInt(1) + " | " );
    System.out.print(res.getString(2) + " | " );
    System.out.print(res.getString(3) + " \n " );
    public TesterApplication() throws SQLException,ClassNotFoundException {
    try {
    setConnection();
    getResultFromSP();
    } finally {
    if (res != null) { res.close(); res = null; }
    if (stmt != null) { stmt.close(); stmt = null; }
    if (connection != null) { connection.close(); connection = null; }
    public static void main(String[] args) {
    try {
    TesterApplication ta = new TesterApplication();
    } catch (Exception e) {
    System.err.println("Error while executing stored procedure " + e.getMessage());
    e.printStackTrace();
    When I run the TesterApplication, I get the following exception :
    java.sql.SQLException: Invalid column type: get_internal_type
    at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(Compiled Code)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(Compiled Code)
    Also, if I want to execute the ResultSet in the stored proc itself, and return the values as Arrays of int[], and String[], how do I do it?By default the you can populate only int[0], String[0] , i.e. only one value!!!
    if my statement is unknown, i.e, it might return a combination of updates and resultsets, how do I go about processing the result?
    Please advise!!
    TIA
    Sandeep
    null

    Hi kkirk,
    I found the post you mentioned.Well it dates back to November 1999 - "Problem returning resultset or ARRAY from java stored proc" by Stuart Popejoy ([email protected]).Too bad, it is still not solved!!
    I am not very good at PL/SQL.However, it would still be helpful, if you could post the code here, or at my email address.
    Meanwhile, I was trying this during the week-end.There seems to be a glimmer of hope!!
    Let me know, if this makes sense :
    CallableStatement cs = connection.prepareCall("begin open ? for select * from dept; end");
    try {
    cs.registerOutParameter(1,OracleTypes.CURSOR);
    ResultSet res = ((OracleCallableStatement)cs).getCursor(1);
    while (res.next()) {
    //get the values
    } catch (Exception e) {
    e.printStacktrace();
    However, I am getting an exception trace
    Error while executing stored procedure Invalid column type: getLong
    java.sql.SQLException: Invalid column type: getLong
    at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.getLongValue(Compiled Code)
    Not quite sure why this is happening!!
    TIA,
    Sandeep
    null

  • Database connection problem when i try store the values in JTable

    Hi Sir,
    I have a database connection problem when i try to store the data's in a JTable.I think the problem is with in the database connection.I have used 3 vectors here.The database which i have used is
    Access.Where the program is compiling well.But when i run it only the first column heading is printed and error message showing that
    "Invalid Cursor State".I need to solve this problem.pls. do help me.
    I will provide u with the code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.sql.*;
    public class DataBaseVector extends JPanel
    //Container contentPane=getContentPane();
    JScrollBar jsb = new JScrollBar(JScrollBar.HORIZONTAL);
    JScrollBar jsb1 = new JScrollBar(JScrollBar.VERTICAL);
    Image i1;
    String url="jdbc:odbc:Ananth";
    Vector col=new Vector();
    Vector rows=new Vector();
    Vector rdata=new Vector();
    Connection conn;
    public DataBaseVector()
    //super("JTable With ScrollBars");
    this.setLayout(new BorderLayout());
    UIManager.put("ScrollBar.track",Color.red);
    UIManager.put("ScrollBar.thumb",Color.blue);
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection(url); // Is there any problem here?
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery("Select * from AccountMaster");
    // rs is the result set obtained
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
    for(int i=1;i<=cols;i++)
    col.addElement(rsmd.getColumnName(i));
    rdata.addElement(rs.getString(i));
    rows.addElement(rdata);
    }catch(Exception e)
         System.out.println("The Error Message was:"+e.getMessage());
    JTable jt=new JTable(rows,col);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp=new JScrollPane(jt,v,h);
    this.add(jsp,BorderLayout.CENTER);
    this.add(jsb, BorderLayout.SOUTH);
    this.add(jsb1, BorderLayout.EAST);
    public static void main(String args[])
    JFrame jf=new JFrame();
    JPanel frame=new DataBaseVector();
    jf.getContentPane().add(frame);
    jf.setSize(800,600);
    jf.setVisible(true);
    Thanx,
    m.ananthu

    The problem is ResultSet.next() is not called.
    Try this and modify the table creation as you need.
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
         while(rs.next()) {
              for(int i=1;i<=cols;i++)
                        col.addElement(rsmd.getColumnName(i));
                        rdata.addElement(rs.getString(i));
              rows.addElement(rdata);
    Hope this helps

  • Problem in rs.next() execution

    Hai guys,
    I had servlet program, this will call the DynamicProcedureDAO.getGroupData() method three times. Every time the getGroupData() method going to call the different oracle (10 g) stored procedure.
    For first two times it works fine, because stored procedure handles fewer amounts of records. But for the third procedure call, system hanged in >> while (rs.next()) statement. I waited for the result almost 20-30 minutes, but i didn't get the result.
    Third oracle procedure manipulate large amount of data. I ran the oracle procedure in database server, it work fine, it returns 60- to 100 rows.
    For more information about code is given below.
    Have you guys experienced any similar problem with Resultset before? Would really appreciate any help or tips from the experts here... thx...
    Saravanan.
    (Mail me : [email protected])
    public class DynamicProcedureDAO extends DAO
    �.
    public ArrayList getGroupData(CCReportObject ccReportObject ,ReportFieldGroup reportFieldGroup) throws StorageException
         Connection con = null;
    CallableStatement cs = null;
    ResultSet rs = null;
    try
    con = super.getConnection();
    String sql = "{call "+ procName +" (?,?,?,?,?,?,?,?,?,?,?,?)}";
    cs = con.prepareCall(sql);
    �..
    �..
    cs.execute();
    rs = ((OracleCallableStatement)cs).getCursor(12);

    int j = rs.getMetaData().getColumnCount();
    DwsLogs.CC_TRACE_LOG.logp(Level.INFO,"DynamicProcedureDAO", "getGroupData ", "Outside wile loop.");
    while (rs.next())
              DwsLogs.CC_TRACE_LOG.logp(Level.INFO,"DynamicProcedureDAO", "getGroupData ", " Inside While Loop");
    The above DwsLogs statements is not executed.

    To expand on schapel.
    myObject.getClass().getMethod("myMethod2", new Class[0]).invoke(myObject, new Object[0]);will invoke the method called "myMethod2" on the Object myObject. The Class[] and Object[] arrays hold the ordered parameter types and values for the method respectively. In this case, myMethod2 is assumed to have no parameters.
    Primitive parameters/return values in the reflection API are replaced by their wrapper classes. As an example, if I have a method called getInt on the class MyClass that takes a float and returns an int, then you would invoke it thus:
    Integer i = new Integer(12);
    Method m = MyClass.class.getMethod("getInt", new Class[]{ Float.TYPE });
    Float float = (Float)m.invoke(myClassInstance, new Object[]{ i });
    Float f = float.floatValue();When dynamically invoking a static method, you can supply null as the instance upon which to invoke the method

  • TopLink and ResultSet: ojdbc14 vs. ojdbc6 - Closed command

    Hi all,
    I have problem with ojdbc library. We updated our ojdbc library from ojdbc14 to ojdbc6. But now, we have problem with SQLExcpetion: "java.sql.SQLException Closed statement".
    We have following code:
    Object result = session.executeQuery(query, args);
    Map map = (Map)((Vector)result).firstElement();
    // the data is in data type OracleResultSetImpl !!!
    OracleResultSet out_data = (OracleResultSet) map.get(EmtasConstant.GRID_PROCEDURE_DATA_OUT);
    OracleResultSetMetaData metadata = (OracleResultSetMetaData) out_data.getMetaData();
    If we used library "ojdbc14.jar" everything works fine, we get metadata, read data from resultSet, etc... No problem!
    But if we using "ojsbc6.jar" and call getMetadata, then throws: "java.sql.SQLException: Closed command: getMetaData" .. or "ava.sql.SQLException: Closed command: next()" or whatever we call on OracleResultSet out_data (we try OracleResultSet and ResultSet too)..
    If we used "ojdbc14.jar" and I call out_data.close(), they throws same exception => Why is the ResultSet in library ojdbc6.jar closed??????
    Any idea? I'm really stuck and I all day trying to come to solve the problem, but I resolved nothing.
    Pls help!
    Thx!
    Best regards, KLD!
    Sry for my English ;)

    Yes, I have newest version of TopLink (11.1.1. ...) and Java (1.6_09).
    Or, is any option how to convert ResultSet to any "normal" java object (like hasmap,collection, list, ...)
    I returned multiple cursor objects from stored procedure, and I resolved it as follows:
    More output cursors with StoredProcedureCall?
    but now I have problem with ResultSet and i don't want call more times the procedure call (first option)...

Maybe you are looking for

  • Screens not working in ECC 6 after upgradation from 4.6c.

    Hi, The custom developed screens which where developed in 4.6c version is not working properly in ECC 6 after upgradation.Do i have to make any more changes for this .? If anyone have an idea please help me in this issue.The custom developed things a

  • How do i create an output file

    i have a 30 page invoice. i only need to email certain pages to someone. is it possible to print a page range to file and email someone that file? any help would be much appreciated

  • Trouble using the counter on PCI 6025E

    Hello, I am facing a problem with the counter on PCI 6025E. I am trying to count the number of pulses generated by the shaft encoder mounted on the shaft of a motor. I am using a channel from the shaft encoder to count the pulses and generate the lin

  • NTSC All regions DVD on Region 2 player?

    I seem to recall that many (maybe most or even all?) PAL DVD players are able to play NTSC discs, if an NTSC DVD was created with all of the region options enabled would a region 2 player be able to play it?

  • Lens Profile for Ricoh GRIII

    I created my first profile, it's for the Ricoh GRDIII. Lightroom users can find it at http://rapidshare.com/files/410020877/G ... W.lcp.html I have taken sets at 30cm and 150 cm, both at F/1.9 and f/4.0 I haven't gone beyond f/4.0 as I normally don't