Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Convert a sqlsessionfactory session.SelectList ArrayList to a Java ResultSet

  1. #1
    Junior Member viper75's Avatar
    Join Date
    Nov 2012
    Location
    Zambia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Convert a sqlsessionfactory session.SelectList ArrayList to a Java ResultSet

    Hi All, I have been wrecking at this issue for two days now, kindly assist , here is my code below . I'm retrieving a query result from my postgressql database using mybatis. The mybatis part works fine . What i want to do is to be able to printout the elements in the query result to the screen. And I keep getting the error


    Exception occurred during event dispatching:
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.sql.ResultSet
    at org.elmis.facility.controllers.facilityproductsset upsessionmapperscalls.selectAllFacility_Approved_P roducts(facilityproductssetupsessionmapperscalls.j ava:38)
     
    @SuppressWarnings("unchecked")
    	public ResultSet  selectAllFacility_Approved_Products(){
     
    		SqlSession session = sqlSessionFactory.openSession();
     
    		try {
    			ResultSet RSapprovedproducts =  (ResultSet) session.selectList("getAllFacilityApprovedProducts");
     
     
     
     
    			while (RSapprovedproducts.next()) {
    		         int factypeId = RSapprovedproducts.getInt("facilitytypeid");
    		         int progprodId = RSapprovedproducts.getInt("programproductid");
    		         int id = RSapprovedproducts.getInt("id");
    		         int progId = RSapprovedproducts.getInt("programid");
    		         int prodId = RSapprovedproducts.getInt("productid");
    		         String pcode = RSapprovedproducts.getString("code");
    		         String pname = RSapprovedproducts.getString("primaryname");
    		         int pbeginbal = RSapprovedproducts.getInt("beginningbalance");
    		         int stock = RSapprovedproducts.getInt("stockinhand");
     
    		         System.out.println(factypeId + "  " + progprodId+"   "+id +" "+progId+
    		        		 " " + prodId+ " "+ pcode+" "+ pname+" "+pbeginbal+"  "+stock );
    		      }
    		      System.out.println();
    		      System.out.println();
     
    			return RSapprovedproducts;
    		}catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} 
     
    		finally {
     
    			session.close();
    		}
    	   	return null;
     
    	}


  2. #2
    Junior Member qazi's Avatar
    Join Date
    Jul 2013
    Location
    Peshawar, Pakistan
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Convert a sqlsessionfactory session.SelectList ArrayList to a Java ResultSet

    you can't understand what exception is saying ?
    Regards Qazi

  3. #3
    Junior Member viper75's Avatar
    Join Date
    Nov 2012
    Location
    Zambia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Convert a sqlsessionfactory session.SelectList ArrayList to a Java ResultSet

    Quote Originally Posted by qazi View Post
    you can't understand what exception is saying ?
    I understand the exception a bit bear with me this is my first java code project , except , i have no implementation knowledge on how to create a result set from an Array list , I thought a cast would work , but not so. Thanks

Similar Threads

  1. convert arraylist to 2D array
    By ishrne in forum Object Oriented Programming
    Replies: 5
    Last Post: April 5th, 2013, 07:57 AM
  2. [SOLVED] How convert sting name as an arrayList name?
    By Purple01 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 27th, 2012, 07:46 AM
  3. ArrayList<String> convert to lowercase
    By s_mehdi76 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2010, 09:05 PM
  4. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM
  5. convert arraylist to a hash map
    By nadman123 in forum Collections and Generics
    Replies: 1
    Last Post: July 29th, 2009, 04:24 AM