Karol R.

Karol R. Projektant /
Programista

Temat: JDBC rekordy aktualizowane

Witam,

Mam dziwny problem z budowaniem aktualizowanych rekordów bazy danych Oracle. Gdy w zapytaniu używam SELECT * do pobrania wszystkich kolumn uzyskany rekord nie da się edytować, gdy wypisze wszystkie nazwy kolumn w konstrukcji SELECT wtedy wszystko jest ok. Oto fragment kodu, który obrazuje problem:

"
java.sql.Statement stat = conn.createStatement(
java.sql.ResultSet.TYPE_SCROLL_SENSITIVE,
java.sql.ResultSet.CONCUR_UPDATABLE);
java.sql.ResultSet rs_all = stat.executeQuery("SELECT * FROM Guests");

System.out.println(rs_all.getConcurrency() == java.sql.ResultSet.CONCUR_UPDATABLE);
//return false

java.sql.ResultSetMetaData rsmd = rs_all.getMetaData();
rs_all.close();
StringBuilder columnNames = new StringBuilder();
for(int i=0; i<rsmd.getColumnCount(); ++i) {
if(i != 0)
columnNames.append(", ");
columnNames.append(rsmd.getColumnName(i+1));
}
java.sql.ResultSet rs = stat.executeQuery("SELECT " + columnNames + " FROM Guests");

System.out.println(rs.getConcurrency() == java.sql.ResultSet.CONCUR_UPDATABLE);
//return true
"

Ktoś spotkał się z podobnym działaniem JDBC i wie z czego to wynika? Z góry dzięki za odpowiedź.
Kamil Mikołajczyk

Kamil Mikołajczyk programista Java /
Grails

Temat: JDBC rekordy aktualizowane

http://www.exampledepot.com/egs/java.sql/CreateUpdatab...
The query of an updatable result set must specify the primary key as one of the selected columns and select from only one table. For some drivers, `SELECT * FROM my_table' will return a read-only result set, so make sure that you specify the column names. 


http://careerride.com/JDBC-updatable-ResultSet.aspx
The query that obtains the rows for updatable must specify the primary key as one of the columns selected and from only one table. Ensure that the columns are specified in select statement explicitly instead of asterisk(*) in select statement.


a przede wszystkim:
http://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/ge...
If queries adhere to the following guidelines, a developer can generally expect that they will produce updatable result sets:

The query references only a single table in the database
The query does not contain a join operation or a GROUP BY clause
The query selects the primary key of the table it references

If inserts are to be performed on the result set, an SQL query should satisfy conditions one through three plus the following three additional conditions:
The user has read/write database privileges on the table
The query selects all of the nonnullable columns in the underlying table
The query selects all columns that do not have a default value
Karol R.

Karol R. Projektant /
Programista

Temat: JDBC rekordy aktualizowane

Kamil Mikołajczyk:
http://www.exampledepot.com/egs/java.sql/CreateUpdatab...
 For some drivers, `SELECT * FROM my_table' will return a read-only result set, so make sure that you specify the column names. 

Dzięki.

Następna dyskusja:

JDBC + MySQL - polskie znaki




Wyślij zaproszenie do