Results 1 to 4 of 4
  1. #1
    spikenigma is offline Member
    Join Date
    Jan 2012
    Posts
    6
    Rep Power
    0

    Default SQL commands on a CachedRowSet completely offline?

    hi,

    I'm looking to create an offline database that will allow SQL commands parsed from Java to interrogate the data without any sort of Connection object if at all possible.

    On the main Oracle site, it states that: [i]"A CachedRowSet object typically contains rows from a result set, but it can also contain rows from any file with a tabular format". It then doesn't go into how. Theoretically, could I say make a connection with say a .csv file and read it into a CachedRowObject which will allow me to SQL-interrogate it?

    I am hoping not to have to:

    a) Install any weird and wonderful classes in the classpath.
    b) Install any third-party additions.
    c) Amend the server directly to define a datasource.

    My (hastily assembled) code with the errors and my pitiful attempts in the comments:


    Java Code:
    import com.sun.rowset.*;
    import com.sun.rowset.CachedRowSetImpl;
    import java.awt.*;
    import java.io.*;
    import java.io.IOException;
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import java.sql.*;
    import javax.sql.*;
    import javax.sql.rowset.*;
    
    
    
          
    public class CreateNewTable 
    {
    
    
        public CreateNewTable()
        {
           try
        {
            		
    				/* create a new CachedRowSetImpl */
    				CachedRowSetImpl crset = new CachedRowSetImpl();
                crset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
                crset.setConcurrency(ResultSet.CONCUR_UPDATABLE); 
    				crset.setUsername("juanvaldez");
                crset.setPassword("espresso");
        			/* create a new CachedRowSetImpl */        
                
                
    				/* create two columns name and id */
    				RowSetMetaData rsMD = new RowSetMetaDataImpl();
    				rsMD.setColumnCount(2);
                rsMD.setColumnName(1, "name");
                rsMD.setColumnType(1, Types.VARCHAR);
                rsMD.setColumnName(2, "id");
                rsMD.setColumnType(2, Types.VARCHAR);
    				/* end of create two columns name and id */
    				
    				
    				/* set the table name and the data source name */
    				rsMD.setTableName(1, "survey");
                rsMD.setTableName(2, "survey");
                crset.setDataSourceName("jdbc/survey");
    				crset.setMetaData(rsMD);
      				/* set the table name and the data source name */		
    	 
    	         
               /* a few memory saving items */	         
                crset.setMaxRows(20);
         			crset.setPageSize(4);
               /* a few memory saving items */	         
    
                
                /* add some data directly to the CachedRowSet */
                crset.moveToInsertRow();
    				crset.updateString("name", "Shakespeare");
    				crset.updateString("id", "12354511");
    				crset.insertRow();
    				crset.updateString("name", "Hamlet");
    				crset.updateString("id", "12354513");
    				crset.insertRow();
    				crset.moveToCurrentRow();      
    				/* add some data directly to the CachedRowSet */
                
    				
    				/* set up a simple SQL command */  
    				crset.setCommand("SELECT * FROM survey");  
    				/* set up a simple SQL command */
    				     
    
    				/* ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* BITS THAT I NEED WHICH PRODUCE ERRORS, just a way of feeding an SQL query in and getting an answer *~*~*~*~*~*~*~*~*~*~*~*~ */
                
    				
    				/* Attempt 1*/
    				/* CreateNewTable.java:75: error: Statement is abstract; cannot be instantiated */
    				/*Statement stmt = new Statement("SELECT * FROM survey");
    				ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); 
    				/* CreateNewTable.java:75: error: Statement is abstract; cannot be instantiated */
    				
    				
    				
    				/* Attempt 2*/
    				/* CreateNewTable.java:84: error: no suitable method found for execute(String) /
    				ResultSet rs = crset.execute("SELECT * FROM survey");
    				/* CreateNewTable.java:84: error: no suitable method found for execute(String) /
    				
    				
    								
    				/* ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* BITS THAT I NEED WHICH PRODUCE ERRORS, just a way of feeding an SQL query in and getting an answer *~*~*~*~*~*~*~*~*~*~*~*~ */
            
    				
                
        			      
                
    				
    				
    				    
             /* reads from the cachedrowset to check if there is anything in it */
              while (crset.next()) {
            	String name = crset.getString(1);
              String id = crset.getString(2);    
              System.out.println("Contents of CachedRowSet: " + name + "  " + id + "  ");
              /* reads from the cachedrowset to check if there is anything in it */
                
                     
        }
                
        }
        catch(Exception e){
            System.err.println("Crumbs!, an error!: " + e + "");
        }
    
        }
        
        
        public static void main(String args[])
        {
        new CreateNewTable();
        }
    
        
    
    }



    Thanks in advance :)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: SQL commands on a CachedRowSet completely offline?

    The CachedRowSet simply represents data from a single query (or from a single file).
    It's not intended to be searchable using SQL.
    It's intended to provide a cache.

    Why are you trying to avoid a connection?

  3. #3
    spikenigma is offline Member
    Join Date
    Jan 2012
    Posts
    6
    Rep Power
    0

    Default Re: SQL commands on a CachedRowSet completely offline?

    I'm trying to avoid creating a Connection object only because every implementation I've seen of it online requires either an online database url or a third-party classes to interact with the specific database.

    Any help creating a Connection object to say a local file (if there is a way) would be greatly appriciated

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: SQL commands on a CachedRowSet completely offline?

    You'd need to write your own JDBC version then, as far as I know.
    There's nothing like this in JavaSE.

    TO be honest you'd probably do better to go with an embedded database, something like Derby or H-thingy.

Similar Threads

  1. How can i run this Applet offline?
    By echo9 in forum Java Applets
    Replies: 0
    Last Post: 10-23-2010, 07:41 PM
  2. Offline browsing issues
    By stthepan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-16-2010, 07:50 AM
  3. Sorting CachedRowset
    By Sayed in forum Advanced Java
    Replies: 0
    Last Post: 07-18-2008, 12:14 PM
  4. connect JDBC to offline database
    By nancyhung in forum JDBC
    Replies: 1
    Last Post: 04-11-2008, 11:04 PM
  5. Offline Web browser
    By one198 in forum New To Java
    Replies: 6
    Last Post: 08-02-2007, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •