Passing a resultset to a method

Hi all,
I want to pass a resultset object that is scrollable and updateable to a method. THe problem is that, the resultset object in the other method is not scrollable or updateable anymore.
Eg.
Statement stat = null;
ResultSet rs = null;
stat = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATEABLE);
rs = executeQuery("SELECT * from table");
rs.absolute(5); // when i use this, it works fine here, but it won't if i pass rs to another method
method2(rs);
// end of this method
method2(ResultSet rs) {
absolute(5); //this is where i am told that ResultSet is readonly and not updateable
OFFCOURSE, ignore the syntax errors and stuff. I would greatly appreciate your help. I really need to figure this out otherwise i would have to rewirte a huge part of my code. Thank you very much

warnerja is only partially right, it is true that database driver sometimes doesn't support updateable resultset, but my problem was solved by following this link
http://www.oracle.com/forums/message.jsp?id=396810&pgm=otn&uid=1024413365365 (you have to register with oracle for that)
for anybody who can't access the above page, the solution is
instead of doing (SELECT * from abc), do (SELECT abc.* from abc)
that should solve your problem if its the same as mine.
HOWEVER, if i have multiple tables and if i do the following as above
SELECT abc.*, zzz.channel, zzz.channel2, xyz.field1
FROM abc, zzz, xyz
the resultset remains readonly, i dont' know why
ANY IDEAS???????

Similar Messages

  • Problem Generating a Report by passing a Resultset as a datasource

    I am having troubles generating a report using CR for Eclipse 2.0.
    I used the example that shows how do a simple select SQL query to the database and pass the resultset from the query to the report to generate a report from here: https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/201084dc-be66-2b10-64bf-dde4970c9b90
    I used a simple rpt file that simply shows the content of two columns from a table: TXN_TYPE_CD and TXN_STATUS_CD from a POLICY_TXN table.
    Using the code above, and just modifying it a bit to include my jdbc connection details as well as my select query, I was able to view the report which populated data from my database (Oracle 10g) at runtime of the application.  This test proved positive.
    However, the problem I am having is that I am trying to make this code into a Servlet for use in a Java EE application running on Websphere 6.1.0.17 using JVM 1.5.0_15  64-bit.  Instead of using the DHTML thick client, I export to PDF.  When I do this, the crystal report shows as a PDF, but the data is missing for some reason.  Only the headers for the two db columns are shown.  I don't see any startling differences between the code and am 100% positive that my resultset is being returned with data (I output the data returned in the result set as shown in the code).
    Here is the code I am using:
    public class CrystalReportGeneratorServlet_WOW extends Servlet {
         private static final long serialVersionUID = 768970549082466125L;
         protected HttpSession session;
         private final String EXPORT_FILE = "myExportedReport.pdf";
         private final String CUSTOM_PATH = "/custom/resource/crystalReport/";
         private String REPORT_NAME;
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws IOException, ServletException {
              Properties loParms = new Properties();
              ResultSet resultSet = null;
              //Obtain current JDBC Connection
              Connection loConn = AppEnvironment.getJDBCConnection();
              Statement statement = null;
              try {
                   REPORT_NAME = "Test.rpt";
                   //Open report
                   ReportClientDocument reportClientDoc = new ReportClientDocument();
                   reportClientDoc.open(SystemConfig.getAppHome() + CUSTOM_PATH + REPORT_NAME, 0);
                   //Create SQL query.    
                   String query = "SELECT \"POLICY_TXN\".\"TXN_TYPE_CD\", \"POLICY_TXN\".\"TXN_STATUS_CD\"" + "FROM   \"POLICY_TXN\"";
                   //Query database and obtain the Resultset that will be pushed into the report.  
                   statement = loConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                   //Execute query and return result set.
                   resultSet = statement.executeQuery(query);
                   //Look up existing table in the report to set the datasource for and obtain its alias.  This table must
                   //have the same schema as the Resultset that is being pushed in at runtime.  The table could be created
                   //from a Field Definition File, a Command Object, or regular database table.  As long the Resultset
                   //schema has the same field names and types, then the Resultset can be used as the datasource for the table.
                   String tableAlias = reportClientDoc.getDatabaseController().getDatabase().getTables().getTable(0).getAlias();
                   /////TESTING: OUTPUT contents of resultSet
                   while (resultSet.next()) {
                        System.out.println("TXN_STATUS_CD = " + resultSet.getString("TXN_STATUS_CD"));
                        System.out.println("TXN_TYPE_CD = " + resultSet.getString("TXN_TYPE_CD"));
                   //Push the Java ResultSet into the report.  This will then be the datasource of the report.
                   DatabaseController dbc = reportClientDoc.getDatabaseController();
                   dbc.setDataSource(resultSet, tableAlias , "resultsetTable");
                   //Export to PDF
                   ExportToPDF(reportClientDoc, response);
              catch(ReportSDKException ex) {     
                   System.out.println(ex);
              catch(Exception ex) {
                   System.out.println(ex);               
              } finally {
                   try {
                        resultSet.close();
                   } catch (SQLException e) {
                             e.printStackTrace();
                        } finally {
                             AppEnvironment.returnStatement(statement);
                             AppEnvironment.returnConnection ( loConn ) ;
         private void ExportToPDF(ReportClientDocument rcd, HttpServletResponse response)
              try {
                   ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
                   rcd.close();
                   writeToBrowser(byteArrayInputStream, response, "application/pdf", EXPORT_FILE);
              catch(ReportSDKException ex) {
                   System.out.println(ex);
              catch(Exception ex) {
                   System.out.println(ex);
         * Utility method that demonstrates how to write an input stream to the server's local file system.
         private void writeToBrowser(ByteArrayInputStream byteArrayInputStream, HttpServletResponse response, String mimetype, String exportFile) throws Exception {
              //Create a byte[] the same size as the exported ByteArrayInputStream.
              byte[] buffer = new byte[byteArrayInputStream.available()];
              int bytesRead = 0;
              try{
                   //Set response headers to indicate mime type and inline file.
                   response.setHeader("Content-disposition", "inline;filename=" + exportFile);
                   response.setContentType(mimetype);
                   //Stream the byte array to the client.
                   while((bytesRead = byteArrayInputStream.read(buffer)) != -1) {
                   response.getOutputStream().write(buffer, 0, bytesRead);
                   //Flush and close the output stream.
                   response.getOutputStream().flush();
                   response.getOutputStream().close();
              } catch (Exception e){
                        e.printStackTrace();
         public static Servlet getInstance()
            return new CrystalReportGeneratorServlet_WOW();
    Any help would greatly be appreciated.

    Actually Uzair I came across this thread in trying to find a resolution to my problem.  I was wondering if you were able to resolve this issue as it appears as though I may have the same problem.
    Thanks.

  • In BADi , How to pass the values between two Method

    Hi Experts,
    We have two methods in BADis. How to pass the value  between two Methods. Can you guys explain me out with one example...
    Thanks & Regards,
    Sivakumar S

    Hi Sivakumar!
    Create a function group.
    Define global data (there is a similiar menu point to jump to the top include).
    Create one or two function modules, with which you can read and write the global data.
    In your BADI methods you can access the global data with help of your function modules. It will stay in memory through the whole transaction.
    Regards,
    Christian

  • How to call a java method so I can pass a file into the method

    I want to pass a file into a java method method from the main method. Can anyone give me some help as to how I pass the file into the method - do I pass the file name ? are there any special points I need to put in the methods signature etc ?
    FileReader file = new FileReader("Scores");
    BufferedReader infile = new BufferedReader(file);
    Where am I supposed to put the above text - in the main method or the one I want to pass the file into to?
    Thanks

    It's a matter of personal preference really. I would encapsulate all of the file-parsing logic in a separate class that implements an interface so that if in the future you want to start taking the integers from another source, e.g. a db, you wouldn't need to drastically alter your main application code. Probably something like this, (with an assumption that the numbers are delimited by a comma and a realisation that my file-handling routine sucks):
    public class MyApp{
    public static void main(String[] args){
    IntegerGather g = new FileIntegerGatherer();
    Integer[] result = g.getIntegers(args[0]);
    public interface IntegerGatherer{
    public Integer[] getIntegers(String location);
    import java.io.*;
    public class FileIntegerGatherer implements IntegerGatherer{
    public Integer[] getIntegers(String location){
    FileInputStream fs=null;
    try{
    File f = new File(location);
    fs = new FileInputStream(f);
    byte[] in = new byte[1024];
    StringBuffer sb = new StringBuffer();
    while((fs.read(in))!=-1){
    sb.append(new String(in));
    StringTokenizer st = new StringTokenizer(sb.toString(),",");
    Integer[] result = new Integer[st.countTokens()];
    int count = 0;
    while(st.hasMoreTokens()){
    result[count]=Integer.valueOf(st.nextToken());
    count++;
    catch(IOException e){
    //something sensible here
    finally{
    if(fs!=null){
    try{
    fs.close();
    catch(IOException f){
    return result;
    Once compiled you could invoke it as java MyApp c:\myInts.txt
    Sorry if there are typos in there, I don't have an ide open ;->

  • How to pass table to in a method as a parameter

    Hi
    I need to pass one table in one method to another method as a parameter.
    ex: it_tab type zvalue(DDIC).
         send_mail( it_tab)like this i need to pass. How to do this.
    Please help me.
    Thanks & Regards
    SUN

    Hello,
    You'll need a table category that has the same structure of your internal table. Suppose you need to pass an internal table of type SCARR: you'll actually pass a parameter of type SCARR_TAB (look for it into tcode SE11).
    Remember that in a OOP scope, you cannot have header line in your internal tables.
    Regards,
    Andre

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • Passing select-options value in method

    How to pass select-options value in method ?
    Example:
    Select-options: carrid for spfli-carrid.
    class cl_myclass implementation.
    select  carrid connid from
    spfli where carrid in carrid.
    endclass.
    Thanks

    Hello Anee
    The coding of this functionality is quite simple:
    REPORT zmy_report.
    DATA:  go_myclass   TYPE REF TO zcl_myclass,
               gd_repid         TYPE syst-repid.
    PARAMETERS:
      p_bukrs   ...
    SELECT-OPTIONS:
      o_kunnr  ...
    START-OF-SELECTION.
      gd_repid = syst-repid.
      CREATE OBJECT go_myclass
        EXPORTING
          id_calling_program = gd_repid.
    And that's how your CONSTRUCTOR method should look like:
    METHOD constructor.  " IMPORTING parameter id_calling_program
    CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
      EXPORTING
        CURR_REPORT = id_calling_report
      TABLES
        SELECTION_TABLE = me->mt_selopts.
    " NOTE: define mt_selopts as instance attribute of table type RSPARAMS_TT
    ENDMETHOD.
    Finally you have to extract the parameter and select-options from MT_SELOPTS.
    Regards
      Uwe

  • Pass an arrayList into a method

    I am looking to pass and  arraylist into a method and I am wondering how this is done...

    I figured it out:
    public function someMethod(someArray:ArrayList){}
    I figured it was the same.
    This is dealing with flex, How ever on the AS side, so its a pure AS question

  • Passing custom DTO to input method...

    Hi,
    Im attempting to create a workshop web service that accesses an EJB control. The
    method's input params require the passing of a custom built data transfer object
    (bean) that contains itself other objects. is there any way to do this via a web
    service thru workshop?

    John,
    A workshop web service (i.e. a JWS file) is analogous to a JSP/servlet. Any
    class (bean) that needs to be passed to an EJB Control method should be
    accessible to the contaning JWS.
    So the bean and all the objects contained/referenced by the bean should be
    available in any one of the following 3 ways:
    1. System CLASSPATH
    2. In the WEB-INF/lib or WEB-INF/classes directory of the Workshop project
    3. As a Java file in the Workshop project directory.
    I hope this answers your question. Do let me know if I can help further.
    Regards,
    Anurag
    "John Bonham" <[email protected]> wrote in message
    news:3e0f058e$[email protected]..
    >
    Hi,
    Im attempting to create a workshop web service that accesses an EJBcontrol. The
    method's input params require the passing of a custom built data transferobject
    (bean) that contains itself other objects. is there any way to do this viaa web
    service thru workshop?

  • Passing an array from one method to another

    I am passing an array from my "load" method and passing it to be displayed in my "display" method in an applet .
    I made the array a class variable (to be able to pass it to the "display" method).
    The applet runs, but nothing seems to be in the array.The screen says applet started, but nothing else. There does not seem to be any CPU activity.
    Trying to debug this, I have tried to paint the screen during the array build. I never figured out how to do this. So I made this a non applet class, put it in debug, and the array seems to load okay.
    Any help is appreciated.
    This is the applet code:
    import java.applet.Applet;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    public class urla extends java.applet.Applet
    int par1;
    int i = 1;
    int j = 20;
    int m = 0;
    int k = 0;
    String arr[] = new String[1000];
    String inputLine;
        public void load() throws Exception
          try
            URL mysite = new URL("http://www.xxxxxxxxxxxxxx.html");
           URLConnection ms = mysite.openConnection();
           BufferedReader in = new BufferedReader(
           new InputStreamReader(
           ms.getInputStream()));
             while ((inputLine = in.readLine()) != null)
               arr[m] = inputLine;
               m++;
           in.close();
          catch (MalformedURLException e)
            k++;
        public void display(Graphics screen)
          screen.drawString("THE FOLLOWING HAVE ADDED THEIR BIOS:",5 ,5);
          for (int i = 0; i < 20; i++);
            j = j + 20;
            screen.drawString("output - "
            + arr, 5, j);
            repaint() ;
    }

    String arr[] = new String[1000];is this typing mistake????? because if u did it in
    program as well i don think it will work.. the tag is
    innnside array lenght... hope iam saying this right!!no, he had the bold form tags (b and /b inside square brackets) in his previous non-code tagged post. He carried it over to this post and they caused an error. I highly doubt that they were in his actual program. Just delete them.
    Message was edited by:
    petes1234

  • Passing argstrings[1] to another method

    Hello I want to pass argstrings[1] to another method. Other stuff is being passed there to. Before I passed argstrings[1] the other stuff worked, now it does not.
    Please tell me why I am getting compilation errors.
    Thanks
    public static void main(String[] argStrings)
            String filePath = null;
            if(argStrings.length != 0)
                 filePath = argStrings[0];
            else
                 System.out.println("Enter a directory please");// Else you have to enter a directory
                 Scanner scan = new Scanner(System.in);
                    filePath = scan.nextLine();
            String copyDate = argStrings[1];
            Date dateToLookFor = new Date(copyDate);
            listFiles(filePath);// this no longer works as of the new log(datetolookfor)
            log(dateToLookFor);// just wanna pass this to the next method
       private static void log(File[] files, Date dateToLookFor)
       {

    Well i only get one compile error, cheers.
    So please could you help me what i have to do to this mess in order for it to work:
    Or just edit the code as I dont think there is much to do:
    Thanks
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    * This application identifies files which could potentially be archived
    * and copied. A file is to be archived if the last modified date is more
    * than 100 days ago. A file is to be copied if it has been modified since
    * a given time. Only nominated extensions are to be considered. The java.
    * util.Calendar class contains relevant methods for comparing times and dates.
    * For instance, a command line of: java CrawlerApp Knuth 2005-12-28 php html
    * Will nominate for archiving or copying only php or html files in the Knuth
    * directory tree. It will only nominate for copying files modified after
    * midnight on the 28th of December, 2005.
    * The output from this application is two files (called archive.txt and copy.txt)
    * containing the names of files to be archived, and those which may be copied.
    * The names will follow the convention specified in the create application.
    * These two text files must appear in the root directory (Knuth, in this example).
    public class Crawler
       public static void main(String[] argStrings)
            String name = null;
            if(argStrings.length != 0)
                 name = argStrings[0];
            else
                 System.out.println("Enter a directory please");// Else you have to enter a directory
                 Scanner scan = new Scanner(System.in);
                    name = scan.nextLine();
            String copyDate = argStrings[1];
            listFiles(name, copyDate);
       private static void log(String copyDate, File[] files)
            PrintStream archivePS = null;
            PrintStream copyPS = null;
            try
                 archivePS = new PrintStream("archive.txt");
                 copyPS = new PrintStream("copy.txt");
                 // instantiate cutoff Calendar instance to test files with
                   Calendar cutoff = Calendar.getInstance();
                   // time now
               Date now = new Date();
                   // set cutoff time with current time
                   cutoff.setTime(now);
                   // subtract 100 days from current time
                   cutoff.add(Calendar.DAY_OF_YEAR, -100);//
                 Calendar calendar = Calendar.getInstance();
                 for(int j = 0; j < files.length; j++)
                      // get last modified time of file
                      long lastModified = files[j].lastModified();
                      // convert lastModified to a date
                      Date lastMod = new Date(lastModified);
                      // set the time for the Calendar instance with lastMod
                      calendar.setTime(lastMod);
                      // test against cutoff Calendar instance variable
                     if(lastMod.before(cutoff.getTime()))
                           archivePS.println(files[j]);
                         if(lastMod.before(cutoff.getTime()))
                              copyPS.println(files[j]);
                         // I will do copy later, just want to see if this works
            catch(FileNotFoundException fnfe)
                 System.err.println("Log error: " + fnfe.getMessage());
            catch(IOException ioe)
                 System.err.println("I/O exception: " + ioe.getMessage());
       private static void listFiles(String name, String copyDate)
           File f = new File(name);// Try to get a list of files in the directory
           File[] files = f.listFiles();// Make array of all the files in that directory
           log(files, copyDate);
           if(f.isDirectory())// If the argStrings[0] is a directory then do the following
               File[] children = f.listFiles(HTMLfilter);// Make an array of html files
               System.out.println("HTML files in " + name + " directory = " + children.length);
               File[] phpFiles = f.listFiles(PHPFilter);// Make an array of php files
               System.out.println("PHP files in " + name + " directory = " + phpFiles.length);
       private static FileFilter HTMLfilter = new FileFilter()
           public boolean accept(File f)// Accept directory Knuth
               //if(f.isDirectory()) return true;
               String name = f.getName().toLowerCase();
               return name.endsWith("html");
               //if(file is 100 days old)
       private static FileFilter PHPFilter = new FileFilter()
            public boolean accept(File f)
                 //if(f.isDirectory()) return true;
                 String name = f.getName().toLowerCase();
                 return name.endsWith("php");
    }

  • I am passing range table from the method of ODATA Service to FM but In FM range table is becoming initial.What would be the reason for the same?

    I am passing range table from the method of ODATA Service to FM but In FM range table is becoming initial.What would be the reason for the same?

    Vinod, Can you share detail on how are you sending and how are you reading.

  • How do I pass an array to a method?

    Hopefully you guys don't mind answering one of my stupid questions :o(
    I have problem passing an array to a method.
    //Here is the code that calls to the method:
    String[] Folder = new String[19];
    int cnt;
    for(cnt=0; cnt<20; cnt++){
    Folder[cnt] = request.getParameter("searchfolder_name" + (cnt + 1));
    ProcessNotify(Folder[cnt]);
    //================================================================
    //Here the the method that is supposed to take in the array
    private void ProcessNotify(String FolderName[]){
    FolderName = new String[19];
    int cnt;
    for(cnt=0; cnt<20; cnt++){
    System.out.println("Folder Name: " + FolderName[cnt]);
    I got an error that says java.lang.String[] can not be applied to java.lang.String
    I thought "String FolderName[]" is an array? Anyway... I'm confused. If you know the answer, plz let me know :o) big thx
    lil

    ProcessNotify(Folder[cnt]);
    Are you trying to pass the whole array or just one piece from it? What you coded, tried to pass just one piece by specifying a subscript. BTW variable cnt is a subscript out of range.
    If you meant to pass the whole array, just use it's name with no subscript.

  • Passing resultsets in a method

    Hello all I am curious what the general thought/idea is about methods passing result sets to the caller - I am guessing bad idea correct ?

    The reason that I am asking is because I am in a
    situation where I need to be able to docomparisions
    from one resultset to another, and putting all ofthe
    code into one method makes it rather long.
    So don't put all the code in one method! Split up the
    code into tasks and code the tasks.Guess it will just take some engineering, as looking at it right away they all rely on each other, but I bet if I work at it a bit I can get everything split up.
    Thanks again for all the info.
    And no it's not possible to do it all in SQL, as some things are dependant on the previous comparison of 2 tables which require other things etc etc.

  • Passing parameters to an SQL method

    Does any one know how could i pass a set of string values and a double to the following method please ??
    public Object executeSQL(final String sql) throws SQLException
                              Object returnValue      = null;
                              Statement statement     = this.connection.createStatement();
                              boolean hasResultSet    = statement.execute(sql);
                              if (hasResultSet)
                              ResultSet rs            = statement.getResultSet();
                              ResultSetMetaData meta  = rs.getMetaData();
                              int numColumns          = meta.getColumnCount();
                              List rows               = new ArrayList();
                              while (rs.next())
                              Map thisRow = new LinkedHashMap();
                              for (int i = 1; i <= numColumns; ++i)
                              String columnName   = meta.getColumnName(i);
                              Object value        = rs.getObject(columnName);
                              thisRow.put(columnName, value);
                              rows.add(thisRow);
                              rs.close();
                              statement.close();
                              returnValue = rows;
                              else
                              int updateCount = statement.getUpdateCount();
                              returnValue     = new Integer(updateCount);
                              return returnValue;
                              }here is the sql statement i want to excute
    INSERT INTO [Receipt$] ([MastInterferenceID], [Name], [Address], [Town], [County], [AmountPaid]) VALUES ('"+mastID+"','"+name+"','"+address+"','"+town+"','"+county+"','"+amount+"');"all these variables are of type String except for amount which is a double ........ and im passing these parameter from another class called "MainMenuGUI"
    The SQL method at the top is part of an connection that enters data to an excel worksheet
    Thanks for taking the time to read this,
    Seanie.

    Does any one know how could i pass a set of string
    values and a double to the following method please ??
    public Object executeSQL(final String sql) throws
    SQLException
    Object returnValue      =
    Object returnValue      = null;
    Statement statement     =
    Statement statement     =
    this.connection.createStatement();
    boolean hasResultSet    =
    boolean hasResultSet    = statement.execute(sql);
    if (hasResultSet)
    ResultSet rs            =
    ResultSet rs            = statement.getResultSet();
    ResultSetMetaData meta  =
    ResultSetMetaData meta  = rs.getMetaData();
    int numColumns          =
    int numColumns          = meta.getColumnCount();
    List rows               =
    List rows               = new ArrayList();
    while (rs.next())
    Map thisRow = new
    Map thisRow = new LinkedHashMap();
    for (int i = 1; i <=
    for (int i = 1; i <= numColumns; ++i)
    String columnName   =
    String columnName   = meta.getColumnName(i);
    Object value        =
    Object value        = rs.getObject(columnName);
    thisRow.put(columnName,
    thisRow.put(columnName, value);
    rows.add(thisRow);
    rs.close();
    statement.close();
    returnValue = rows;
    else
    int updateCount =
    int updateCount = statement.getUpdateCount();
    returnValue     = new
    returnValue     = new Integer(updateCount);
    return returnValue;
    }here is the sql statement i want to excute
    INSERT INTO [Receipt$] ([MastInterferenceID], [Name],
    [Address], [Town], [County], [AmountPaid]) VALUES
    ('"+mastID+"','"+name+"','"+address+"','"+town+"','"+co
    nty+"','"+amount+"');"all these variables are of type String except for
    amount which is a double ........ and im passing these
    parameter from another class called "MainMenuGUI"
    The SQL method at the top is part of an connection
    that enters data to an excel worksheet
    Thanks for taking the time to read this,
    Seanie.Seanie,
    Why dont you use a Prepared Statement ? That way you will be able to input values to the SQL.
    Cheers!
    Jay

Maybe you are looking for