About TYPE_SCROLL_SENSITIVE of ResultSet
Hi,I used
Connection.prepareStatement( sql,
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY
to get my PreparedStatement,and then when I retrieved data from the ResultSet object,I found that the getObject() method always returned null and getString() method returned wrong encoding Strings. But it's OK when I used common PreparedStatement.I don't know what the hell is going on.
can anybody give me some suggestion? I am working under Oracle 8.1.6 Server & JDBC driver.
thanks very much.
this is a "feature"... :)
don't do "select *"... you must name the columns in the select statement or the driver will change the type to read only...
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Sreenu B ([email protected]):
Hello OTN,
I am able to found a bug in JDBC driver-8.1.7
It is:
When I tried to create a resultset of type: ResultSet.TYPE_SCROLL_SENSITIVE(1005) from prepared statement, I am getting resultset of type: ResultSet.TYPE_SCROLL_INSENSITIVE(1004).
I used this driver with :Oracle-Oracle8i Enterprise Edition Release 8.1.6.1.0.
Please see the code snippet below:<HR></BLOCKQUOTE>
null
Similar Messages
-
Question about updateRow in ResultSet
Simple problem. When I update the values in a resultset with:
rs.updateString("columnName", aString);
rs.updateRow();the value of columnName is updated, but the values of all the other columns in the row are set to nothing. How do I prevent this from happening? Do I have to update all the column values when using updateRow, i.e getting the values from the resultset and then updating with the same values?
- Karl XIIHi Karl,
You could try using the following code:
int numRows = 0;
int empId = 1223;
String updateEmp="update employees set department=?
where id = ?";
PreparedStatement pstmt =
conn.prepareStatement(updateEmp);
pstmt.setString(1,"department");
pstmt.setInt(2,empId);
numRows = pstmt.executeUpdate();
pstmt.close();
This piece of code would only update the columns that
you mention in the PreparedStatement SQL query.
Thanks,
Rashmi.Thanx. But I have a resultSet that is linked to the database. I to only like to edit the value of a specific column in the resultset... any other suggestions? -
Hello,
I'm trying to build an application that returns a record set for evaluation.
I'm want to have a class file do the connection and then return the record set to my main program. How do I go about returning a resultset?just do it.
public ResultSet myMethod() {
ResultSet rs = ...
return rs;
} -
Need help with inserting rows in ResultSet and JTable
hello Guru!
i have inserted a row in my result set and i want that my table shows this row promptly after i have inserted it in my result set...
but when i use following code for my resultset:
rs.moveToInsertRow();
rs.updateInt(1,nr);
rs.updateString(2, name);
rs.insertRow();
Record are inserted in resultset and database but not shown in my JTable??
Anyone a Clue to without reexecuting the query how can i display inserted row in JTable
http://download-west.oracle.com/docs/cd/A87860_01/doc/java.817/a83724/resltse7.h
I have refrered the following links but still clue less help Guruuuuuuu
i m really in trobble??????i am just near by the Solution using the Database Metadata
by couldn't get the ideaaaa
==================================================
http://download-west.oracle.com/docs/cd/A87860_01/doc/java.817/a83724/resltse7.htm
Seeing Database Changes Made Internally and Externally
This section discusses the ability of a result set to see the following:
its own changes (DELETE, UPDATE, or INSERT operations within the result set), referred to as internal changes
changes made from elsewhere (either from your own transaction outside the result set, or from other committed transactions), referred to as external changes
Near the end of the section is a summary table.
Note:
External changes are referred to as "other's changes" in the Sun Microsystems JDBC 2.0 specification.
Seeing Internal Changes
The ability of an updatable result set to see its own changes depends on both the result set type and the kind of change (UPDATE, DELETE, or INSERT). This is discussed at various points throughout the "Updating Result Sets" section beginning on , and is summarized as follows:
Internal DELETE operations are visible for scrollable result sets (scroll-sensitive or scroll-insensitive), but are not visible for forward-only result sets.
After you delete a row in a scrollable result set, the preceding row becomes the new current row, and subsequent row numbers are updated accordingly.
Internal UPDATE operations are always visible, regardless of the result set type (forward-only, scroll-sensitive, or scroll-insensitive).
Internal INSERT operations are never visible, regardless of the result set type (neither forward-only, scroll-sensitive, nor scroll-insensitive).
An internal change being "visible" essentially means that a subsequent getXXX() call will see the data changed by a preceding updateXXX() call on the same data item.
JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
boolean ownDeletesAreVisible(int) throws SQLException
boolean ownUpdatesAreVisible(int) throws SQLException
boolean ownInsertsAreVisible(int) throws SQLException
Note:
When you make an internal change that causes a trigger to execute, the trigger changes are effectively external changes. However, if the trigger affects data in the row you are updating, you will see those changes for any scrollable/updatable result set, because an implicit row refetch occurs after the update.
Seeing External Changes
Only a scroll-sensitive result set can see external changes to the underlying database, and it can only see the changes from external UPDATE operations. Changes from external DELETE or INSERT operations are never visible.
Note:
Any discussion of seeing changes from outside the enclosing transaction presumes the transaction itself has an isolation level setting that allows the changes to be visible.
For implementation details of scroll-sensitive result sets, including exactly how and how soon external updates become visible, see "Oracle Implementation of Scroll-Sensitive Result Sets".
JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
boolean othersDeletesAreVisible(int) throws SQLException
boolean othersUpdatesAreVisible(int) throws SQLException
boolean othersInsertsAreVisible(int) throws SQLException
Note:
Explicit use of the refreshRow() method, described in "Refetching Rows", is distinct from this discussion of visibility. For example, even though external updates are "invisible" to a scroll-insensitive result set, you can explicitly refetch rows in a scroll-insensitive/updatable result set and retrieve external changes that have been made. "Visibility" refers only to the fact that the scroll-insensitive/updatable result set would not see such changes automatically and implicitly.
Visibility versus Detection of External Changes
Regarding changes made to the underlying database by external sources, there are two similar but distinct concepts with respect to visibility of the changes from your local result set:
visibility of changes
detection of changes
A change being "visible" means that when you look at a row in the result set, you can see new data values from changes made by external sources to the corresponding row in the database.
A change being "detected", however, means that the result set is aware that this is a new value since the result set was first populated.
With Oracle8i release 8.1.6 and higher, even when an Oracle result set sees new data (as with an external UPDATE in a scroll-sensitive result set), it has no awareness that this data has changed since the result set was populated. Such changes are not "detected".
JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
boolean deletesAreDetected(int) throws SQLException
boolean updatesAreDetected(int) throws SQLException
boolean insertsAreDetected(int) throws SQLException
It follows, then, that result set methods specified by JDBC 2.0 to detect changes--rowDeleted(), rowUpdated(), and rowInserted()--will always return false with the 8.1.6 Oracle JDBC drivers. There is no use in calling them.
Summary of Visibility of Internal and External Changes
Table 12-1 summarizes the discussion in the preceding sections regarding whether a result set object in the Oracle JDBC implementation can see changes made internally through the result set itself, and changes made externally to the underlying database from elsewhere in your transaction or from other committed transactions.
Table 12-1 Visibility of Internal and External Changes for Oracle JDBC
Result Set Type Can See Internal DELETE? Can See Internal UPDATE? Can See Internal INSERT? Can See External DELETE? Can See External UPDATE? Can See External INSERT?
forward-only
no
yes
no
no
no
no
scroll-sensitive
yes
yes
no
no
yes
no
scroll-insensitive
yes
yes
no
no
no
no
For implementation details of scroll-sensitive result sets, including exactly how and how soon external updates become visible, see "Oracle Implementation of Scroll-Sensitive Result Sets".
Notes:
Remember that explicit use of the refreshRow() method, described in "Refetching Rows", is distinct from the concept of "visibility" of external changes. This is discussed in "Seeing External Changes".
Remember that even when external changes are "visible", as with UPDATE operations underlying a scroll-sensitive result set, they are not "detected". The result set rowDeleted(), rowUpdated(), and rowInserted() methods always return false. This is further discussed in "Visibility versus Detection of External Changes".
Oracle Implementation of Scroll-Sensitive Result Sets
The Oracle implementation of scroll-sensitive result sets involves the concept of a window, with a window size that is based on the fetch size. The window size affects how often rows are updated in the result set.
Once you establish a current row by moving to a specified row (as described in "Positioning in a Scrollable Result Set"), the window consists of the N rows in the result set starting with that row, where N is the fetch size being used by the result set (see "Fetch Size"). Note that there is no current row, and therefore no window, when a result set is first created. The default position is before the first row, which is not a valid current row.
As you move from row to row, the window remains unchanged as long as the current row stays within that window. However, once you move to a new current row outside the window, you redefine the window to be the N rows starting with the new current row.
Whenever the window is redefined, the N rows in the database corresponding to the rows in the new window are automatically refetched through an implicit call to the refreshRow() method (described in "Refetching Rows"), thereby updating the data throughout the new window.
So external updates are not instantaneously visible in a scroll-sensitive result set; they are only visible after the automatic refetches just described.
For a sample application that demonstrates the functionality of a scroll-sensitive result set, see "Scroll-Sensitive Result Set--ResultSet5.java".
Note:
Because this kind of refetching is not a highly efficient or optimized methodology, there are significant performance concerns. Consider carefully before using scroll-sensitive result sets as currently implemented. There is also a significant tradeoff between sensitivity and performance. The most sensitive result set is one with a fetch size of 1, which would result in the new current row being refetched every time you move between rows. However, this would have a significant impact on the performance of your application.
how can i implement this using
JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
boolean deletesAreDetected(int) throws SQLException
boolean updatesAreDetected(int) throws SQLException
boolean insertsAreDetected(int) throws SQLException -
How to use the wl61sp2 of scrollable resultsets
wl61sp2 had already included mssqlserver4 , but it could not support for scrollable
resultsets. How about using scrollable resultsets in the wl61sp2 or install the
mssqlserver4v70rel510sp11 into the wl61sp2? If you can answer these questions,please
help me!!!thanks
Error:
java.sql.SQLException: java.sql.SQLException: This JDBC 2.0 method is not implemented
at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:406)at jsp_servlet._adminwww.__t._jspService(__t.java:108)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at eblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
at eblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2495)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2204)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)wangchuyun wrote:
>
wl61sp2 had already included mssqlserver4 , but it could not support for scrollable
resultsets. How about using scrollable resultsets in the wl61sp2 or install the
mssqlserver4v70rel510sp11 into the wl61sp2? If you can answer these questions,please
help me!!!thanksOur driver is only at the JDBC 1.0 level in functionality. For jdbc 2.0 compliance, I
recommend using either MS's new free type-4 driver or the good driver from
www.inetsoftware.de.
Joe
>
Error:
java.sql.SQLException: java.sql.SQLException: This JDBC 2.0 method is not implemented
at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:406)at jsp_servlet._adminwww.__t._jspService(__t.java:108)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at eblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
at eblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2495)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2204)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120) -
Crystal Reports "Report Application Server"
Does anyone have any experience with Crystal Reports' Report Application Server (RAS)?
The provided documentation is very thin and support are taking an age to respond.
I want to use a Bean as a data source for a report. The blurb says you can do this, but the only documented way I can find is for the bean to return a ResultSet, completely missing the point of using a bean or EJB in the first place.
Now, Seagate's sales blurb states that Beans and EJBs can be used as data sources, but if the only way to do this is to return a common or garden ResultSet, what's the point of the bean???
So, has anyone sucessfully used a bean or EJB as a data source for report generation under RAS, or merely CR in general, without resorting to a ResultSet??Crystal Reports YUK!! especially in Java Forum!Tell me about it!!
But, like many developers, I don't get a choice. I have to use CR, and I have to integrate it into a Tomcat (4.1.24) based app. There is a Java API for RAS, but it is a pile of dung. Can you imagine publishing an API with public methods with 'do not use, for internal use only' plastered all over them!!!
But still, back to the original question, I have to find a way of doing this, but Seagate's javadocs are a mess, as are the howto docs. All of the examples, as you might expect, are childishly simple and don't give any insight into the large and hideous API :(
Here is an example of a CR howto.....
There appear to be two ways of creating a data source that isn't an existing report or a database query. This
Runtime data sources
One of the strengths of RAS over the Crystal Reports application, is that the RAS
can use data generated programatically at runtime. With a runtime data source,
you can take data from any source�such as a database, a data stream, or a flat
file�manipulate it with the programming language of your choice, and display it
with RAS.
To use a runtime data source
1 Put your manipulated data in a rowset form that can be processed by the RAS.
Consult the Rowset object and interface in the SDK JavaDocs, for details on
creating rowsets.
2 Create and fill the Dataset object with the rowset data.
3 Create a RowsetController object.
4 Add or set the data source using the RowsetController�s AddDataSource or
SetDataSource methods respectively.
The runtime data source is now available for use.
Note: If you create a report based on a data set, the data that is used is not saved
with the report. To populate the report with data the next time you open it, you
must either re-apply the data source to see current data, or access a saved version
of the data source for preview.
All well and good, but RowsetController doesn't have an AddDataSource or SetDataSource method!!!!
and this......
JavaBean custom data sources
You can use a JavaBean (or a Java class that does not extend the bean type) in order
to specify a custom data source. In order to do this, you will need to:
� Creating a Java class that specifies a custom data source
� Referencing a java class to provide data for a report
Creating a Java class that specifies a custom data source
To use a JavaBean (or a Java class that does not extend the bean type) in order to
specify a custom data source, you will need to create a class that serves as a Java
Beans Connectivity data source for creating Crystal Reports.
This class will need to conforms to the JavaBean standard by defining private
properties that are accessible only through get and set methods. In this way the
Crystal Reports designer can introspect the class as a Bean. The JavaBean
connectivity classes require the following.
� The constructor must have zero parameters.
� Methods that are used as "tables" must have a return type of ResultSet.
� Statement objects must be created using the
ResultSet.TYPE_SCROLL_SENSITIVE and ResultSet.CONCUR_READ_ONLY
arguments.
Note: Methods returning ResultSet can take arguments, these are treated as
Stored Procedure parameters by Crystal Reports.
Now, what the hell is the point of going to the trouble of abstracting your business data into a bean or EJB, if that bean has to return a ResultSet for Crystal Reports to use??!! -
Should columns only be read once....
Good day,
I have a question about reading the resultset.
I was recently reading the java.sql API.
And in the description for the Resultset interface.
It mentions that "each column should be read only once"
Currently I don't call columns via results.getString("column") directly.
I usually set it to a variable and the use the variable as much as i need.
This method mainly helps me keep organized.
I was wondering if there are any real problems or issues that may arise from calling a column directly a numerous amount of times.
I don't plan on chaning my current method of going about resultsets, but i was just curious.
thanks,
alexHi,
You can scroll through the result set and read a column any number of time (provided proper resultSetType is set during statement creation).
see the scenario where such things will not work (but depends on the driver implementation). suppose u are retrieving rows in bulk (say >10k number of rows of large size).retrieving the bulk will give u out of memory etc exceptions. and if u set the fetchsize(int size)method things will become ok. but here u cant gurantee that u will get the column value on ur second visit to the same column (ie calling rs.getXX()method second time) .
so the rule thumb is retrieve the column value only once and store it in a variable- this is what u are doing rt now (if its a large value, process it on the spot according to ur need)
HTH,
-asharafkk -
Paging results on PHP/Oracle
Does anybody have a clean code they can share about paging query resultset on PHP using OCI (not ADO or something else)???
I've tried some posted here but the results is not encouraging ...Look at
http://asktom.oracle.com/pls/ask/f?p=4950:8:12499734965902645361::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:127412348064
A working example in SQL*Plus:
arc@sles> var nrows number;
arc@sles> var offset number;
arc@sles> exec :nrows := 3;
PL/SQL procedure successfully completed.
arc@sles> exec :offset := 5;
PL/SQL procedure successfully completed.
arc@sles> select rowno,empno,ename from
2 (select rownum as rowno,empno,ename from
3 (select * from scott.emp order by empno)
4 where rownum <= :offset + :nrows)
5 where rowno >:offset;
ROWNO EMPNO ENAME
6 7654 MARTIN
7 7658 CHAN
8 7698 BLAKE
The same in PHP could like something:
$stmt = OCIParse($conn,"select rowno,empno,ename from
(select rownum as rowno,empno,ename from
(select * from scott.emp order by empno)
where rownum <= :offset + :nrows)
where rowno >:offset");
OCIBindByName($stmt,":nrows",$nrows,10);
OCIBindByName($stmt,":offset",$offset,10); ... -
I am a former FoxPro programer who has just started working with the JDBC. I have a quick question about table focus. (I am picking up the JDBC Pocket Reference guide tomorrow so this will hopefully be my only silly question)
How can I retrieve the entire contents of a table to the result set without saying
SELECT * FROM TABLE
This seems this is a very slow alternative to just returning the entire table without going through the whole select process and returning a cursor filled with the data.
In FoxPro (ugh) you can say SELECT TABLE and that would bring the table into focus. Can you do this in Java or are you limited to an entire select statement by the JDBC driver?I'm not a FoxPro programmer, so I don't know what the difference is between SELECT * FROM TABLE and bringing the table into focus. If it's a remote call to a database, that data's gotta come back someway. Those bytes have to cross the network sometime. I don't see the difference, but them I'm ignorant.
Are you saying that "bringing the table into focus" allows you to grab say the first ten records and then ask for the next ten when you're ready for them?
I'm not sure, but you might be talking about a scrollable ResultSet or maybe javax.sql.RowSet.
But I don't know of any way to avoid that SELECT.
Are you 100% certain that it's a problem? Have you timed the two and compared?
I have a funny feeling that FoxPro might be doing that SELECT * FROM TABLE behind the scenes and perhaps doing some nice caching to make it look fast.
Sorry I haven't been much help. Maybe someone who knows both JDBC and FoxPro will be able to answer with authority. - MOD -
Hi
I'm getting a List of Entitys by
String _selectStr = "SELECT a FROM " + GNebenengGruppenverwEntity.class.getSimpleName() + " a";
Query query = getEntityManager().createQuery(_selectStr);
return (Collection<GNebenengGruppenverwEntityIF>) query.getResultList();I'm getting them for read only purposes. But by getting them in this way they are managed by the entity manager. Every time about 13'000 Entitys are created and managed. If a User opens and closes the screan 3 times in a row the EntityManager tries to get these 13'000 Entitys parallel.
Is there a possibility to stop the entityManager from getting the List or at least say him he should get the list but do not manage them (whould at least save some memory).If I use EntityManager.createNativeQuery(String) then I get results which are of course not bound in the entityManager but I have problems to Map all the returned Types like BigDecimal to something useful like Long. If I whould use EntityManager.createNativeQuery(String sql, String resultSetName) then this whould be handled, but is the returned Entity then again handled by the EntityManager?
And 2nd what I'm doing wrong? On the Entity I declared:
@SqlResultSetMapping(name="getList", entities={
@EntityResult(entityClass = GNebenengGruppenverwEntity.class, fields = {
@FieldResult(name = "NEG_KEY", column = "key")
@FieldResult(name = "NEG_BEZEICHNUNG", column = "bezeichnung")
})})and in the Bean I use:
String _selectStr = "SELECT kn.NEG_KEY key, kn.NEG_BEZEICHNUNG bezeichnung FROM re_nebenengagement kn";
final Query query = getEntityManager().createNativeQuery(_selectStr, "getList");
List result = query.getResultList();I always get
java.sql.SQLException: Ung�ltiger Spaltenname
and on the Output from JBoss I have:
DEBUG 2007-10-25 11:18:41,083 [AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG 2007-10-25 11:18:41,083 [ConnectionManager] opening JDBC connection
DEBUG 2007-10-25 11:18:41,099 [SQL] SELECT kn.NEG_BEZEICHNUNG bezeichnung FROM kre_nebenengagement kn
DEBUG 2007-10-25 11:18:41,099 [AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
INFO 2007-10-25 11:18:41,099 *[LongType] could not read column value from result set: NEG1_39_0_; Ung�ltiger Spaltenname*DEBUG 2007-10-25 11:18:41,099 [AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG 2007-10-25 11:18:41,099 [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG 2007-10-25 11:18:41,099 [ConnectionManager] aggressively releasing JDBC connection
DEBUG 2007-10-25 11:18:41,115 [ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG 2007-10-25 11:18:41,115 [JDBCExceptionReporter] could not execute query [SELECT kn.NEG_BEZEICHNUNG bezeichnung FROM kre_nebenengagement kn] -
A question about ResultSet.UpdateObject(int column, Object x)
hi, I write some code which use the TableModel to represent the data fetched from MS-ACCESS.
the problem is about the UpdateObject(...) method which is in the implement of the AbstractTableModel method setAtValue(). when transfered OBJECT TYPE is java.lang.String, I can't get the correct result in the JTable view.
my code is as below, could somebody point me out my problem
public class MyTableModel extends AbstractTableModel {
private ResultSet rs ;
private ResultSetMetaData rsmd;
/** Creates a new instance of MyTableModel */
public MyTableModel() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
String url = "jdbc:odbc:CoffeeBreak";
try {
Connection con = DriverManager.getConnection(url,"","");
String strSQL = "SELECT * FROM COFFEES";
Statement pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pSt.executeQuery(strSQL);
rsmd = rs.getMetaData();
} catch (SQLException ex) {
ex.printStackTrace();
/* table model retrieve the Class type of a column method here*/
public Class getColumnClass(int c){
try {
return Class.forName(rsmd.getColumnClassName(c+1));
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
return String.class;
//method of update database and JTable after user edited a table cell
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
int concurrency = rs.getConcurrency();
if(concurrency == 1008){
rs.absolute(rowIndex+1); //the JTable row index is start from 0,so plus 1
rs.updateObject(columnIndex+1, aValue);//the JTable column index is start from 0, so plus 1
rs.updateRow();
} catch (SQLException ex) {
ex.printStackTrace();
}when the column type is about java.lang.String, the cell's result is incorrect, it looks like "[B@1f8f72f" and database can't update.It's me again.
I post the whole class code here
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
* @author qhj
public class MyTableModel extends AbstractTableModel {
/** Creates a new instance of MyTableModel */
private ResultSet rs ;
private ResultSetMetaData rsmd;
private Statement pSt;
private String strSQL;
public MyTableModel() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
String url = "jdbc:odbc:CoffeeBreak";
try {
Connection con = DriverManager.getConnection(url,"","");
strSQL = "SELECT * FROM COFFEES";
pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pSt.executeQuery(strSQL);
rsmd = rs.getMetaData();
} catch (SQLException ex) {
ex.printStackTrace();
public int getRowCount() {
try {
rs.last();
return rs.getRow();
} catch (SQLException ex) {
ex.printStackTrace();
return 0;
public int getColumnCount() {
try {
return rsmd.getColumnCount();
} catch (SQLException ex) {
ex.printStackTrace();
return 0;
public Object getValueAt(int rowIndex, int columnIndex) {
try {
rs.absolute(rowIndex+1);
return rs.getObject(columnIndex+1);
} catch (SQLException ex) {
ex.printStackTrace();
return null;
public String getColumnName(int column){
try {
return rsmd.getColumnName(column+1);
} catch (SQLException ex) {
ex.printStackTrace();
return "N/A";
public Class getColumnClass(int c){
try {
return Class.forName(rsmd.getColumnClassName(c+1));
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
return String.class;
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
return true;
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
int concurrency = rs.getConcurrency();
if(concurrency == 1008){
rs.absolute(rowIndex+1);
rs.updateObject(columnIndex+1, aValue);
//rs.updateRow();
//rs = pSt.executeQuery(strSQL);
} catch (SQLException ex) {
ex.printStackTrace();
fireTableDataChanged();
} -
Unclear about closing ResultSets
Please provide clarification: The JavaDoc for ResultSets says that you don't have to explicitly close ResultSet objects since the RS will be closed when its defining Statement is closed or when the RS is garbage collected.
The Oracle JDBC Developer's Guide and Reference states (in the section titled "Closing the Result Set and Statement Objects"):
"You must explicitly close the ResultSet and Statement objects after you finish using them. This applies to all
ResultSet and Statement objects you create when using the Oracle JDBC drivers. The drivers do not have
finalizer methods; cleanup routines are performed by the close() method of the ResultSet and Statement
classes. If you do not explicitly close your ResultSet and Statement objects, serious memory leaks could
occur. You could also run out of cursors in the database."
So, does the Oracle driver operate differently than the JDBC standard in this regard?The JavaDoc for ResultSets says that you don't have to explicitly close ResultSet objects since the RS will be closed when its defining Statement is closed or when the RS is garbage collected.In Oracle JDBC, if you close the statement, then the result set is also closed, unless you obtained the result set as an OUT parameter from a stored procedure or function that returns a REF CURSOR.
However, it is definitely not prudent to wait until the result set is garbage collected, since you have no explicit control over that! Depending on your database setup, you'll typically be able to open a couple dozen statements before you start running out of database cursors.
This is even more important if you are using SQLJ: there statements are automatically managed for you, so you'll never have to worry about closing them. However, if you do not close result sets (called iterators in SQLJ), the associated statement will be kept around and stays open (again, it might be garbage collected or it might not - no guarantees). -
What I am trying to do is, get the current row and compare with the previous from the resultset.
To achieve it I am using the previous(), absolute() and next() methods from ResultSet. Now to be able to use these methods I believe I need to define connx as:
Class.forName("oracle.jdbc.driver.OracleDriver");
con1 = DriverManager.getConnection("jdbc:oracle:thin:@uaix02....","....","....");
stmt1 = con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE);
By doing so when I compile from JDeveloper, I am getting the following error:
C:\Program Files\Oracle\JDeveloper 3.2\myhtml\test548_html\untitled10.jsp
Warning: (0) ISO-8859-1 character set may not match project compiler setting.
Error: (82) method createStatement(int) not found in interface java.sql.Connection.
I am importing java.sql and oracle.jdbc libraries.
Any pointers to it would be greatly appreciated.
Thanks in Advance
Ajith
nullFixed...
Actually createStatement() takes zero or no arguments....
kash! the error messages had been more developer friendly....
Ajith -
Bug in ResultSet.TYPE_SCROLL_SENSITIVE
Hello OTN,
I am able to found a bug in JDBC driver-8.1.7
It is:
When I tried to create a resultset of type: ResultSet.TYPE_SCROLL_SENSITIVE(1005) from prepared statement, I am getting resultset of type: ResultSet.TYPE_SCROLL_INSENSITIVE(1004).
I used this driver with :Oracle-Oracle8i Enterprise Edition Release 8.1.6.1.0.
Please see the code snippet below:
PreparedStatement pst = conn.prepareStatement("select * from empdest",
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); //READ_ONLY);
System.out.println("set type: "+ResultSet.TYPE_SCROLL_SENSITIVE); //printing 1005 here.
ResultSet rs = pst.executeQuery();
System.out.println("got type: "+rs.getType()); //printing 1004 here
Is it really a bug or have any alternative!
Please respond to this ASAP.
Regards,
SreenU.this is a "feature"... :)
don't do "select *"... you must name the columns in the select statement or the driver will change the type to read only...
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Sreenu B ([email protected]):
Hello OTN,
I am able to found a bug in JDBC driver-8.1.7
It is:
When I tried to create a resultset of type: ResultSet.TYPE_SCROLL_SENSITIVE(1005) from prepared statement, I am getting resultset of type: ResultSet.TYPE_SCROLL_INSENSITIVE(1004).
I used this driver with :Oracle-Oracle8i Enterprise Edition Release 8.1.6.1.0.
Please see the code snippet below:<HR></BLOCKQUOTE>
null -
MDM iView resultset problem and question about eventing
Hi experts,
I created a MDM iView resultset for my main table as search table (comparison is not supported). When I click on preview I get an empty table ("Found <Tablename>: 0 of 10", table contains 10 entries at the moment). I tried the same with a subtable and everything works fine (all entries have been in the preview table). Any ideas why I don't get a result?
My 2nd question: can I choose the parameter name in eventing (EPCF) on my own? So if I have Vendor_Id as field can I use vendorid as parameter name? Do I have to define anything in the listener iView (e.g. in detail iView for an event from resultset iView)? Maybe you have a useful tutorial link (please not SAP help section)?
Thanks for your answers.
Regards, bdIt is possible to retrieve the number of rows from a resultset --
Statement stmt= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READONLY);
ResultSet rs= stmt.executeQuery("<your select query here>");
int totalRows;
if (rs.last()) // can it move to the last row?
totalRows= rs.getRow(); // get its row number
else
totalRows= 0; // no rows in the resultset
rs.first() // set the cursor back to the startNote that the resultset has to be scrollable (TYPE_SCROLL_INSENSITIVE).
kind regards,
Jos
Maybe you are looking for
-
Hi, we are running ASCP on 11.5.10 and use a forecast from ODP loaded into the ASCP plan. In the plan options we have set "Schedule By" to "Schedule Ship Date" because we want that everything is planned for the Schedule Ship Date from the Sales Order
-
My iphone 4 isn't charging, why?
My iPhone 4 fell out of my pocket the other day and hit the floor, as it has done many times. I carried on as usual, and out it on charge that night. It charged. Last night I put it on charge, apart from, it didn't actually charge. WHY!? I've tried t
-
I need to move my library from my old computer to my new laptop (Windows 8). What's the best way to do this?
-
Sender Mail Adapter - Need to pick all email only with subject "Send to Business Partner "
Hi Experts, I have a mail to file scenario where I need to pick all emails with subject as "Send to Business Partner". I have seen one mail attribute SHeaderSUBJECT. Can I use this attribute to set a condition like SHeaderSUBJECT = "Send to Business
-
HT1918 I'm trying to buy an app, but it keeps telling me to contact iTunes support?
Help please! I need to figure this out.