Results 1 to 4 of 4
- 01-13-2012, 03:42 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
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 :)
- 01-13-2012, 03:53 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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?
- 01-13-2012, 04:19 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
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
- 01-16-2012, 11:12 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Similar Threads
-
How can i run this Applet offline?
By echo9 in forum Java AppletsReplies: 0Last Post: 10-23-2010, 07:41 PM -
Offline browsing issues
By stthepan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-16-2010, 07:50 AM -
Sorting CachedRowset
By Sayed in forum Advanced JavaReplies: 0Last Post: 07-18-2008, 12:14 PM -
connect JDBC to offline database
By nancyhung in forum JDBCReplies: 1Last Post: 04-11-2008, 11:04 PM -
Offline Web browser
By one198 in forum New To JavaReplies: 6Last Post: 08-02-2007, 03:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks