On Sat, 15 Nov 2003, Aminem wrote:

> apakah database mysql tidak bisa diupdate dengan melalui 
> object resultset ? sebab ketika tiap saya execute 

Object resultset itu 'read-only'

> selalu muncul error. atau ada yg salah dalam coding saya ? 
> mohon bantuannya.
> Terima kasih.
> 
> import java.sql.*;
> public class ResultSetUpdateRow{
>       
>       public static void main(String args[]) throws 
> SQLException, ClassNotFoundException{
>               Class.forName("org.gjt.mm.mysql.Driver");
>               Connection cn = 
> DriverManager.getConnection("jdbc:mysql://aminem/test","root","");
>               Statement st = 
> cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
> ResultSet.CONCUR_UPDATABLE);          
>               ResultSet rs = st.executeQuery("Select EMPNO,ENAME,SAL 
> From EMP");           
>               adjustSalary(rs,500);
>               rs.close();
>               st.close();
>       }       
>       
>       public static void adjustSalary(ResultSet rs, double 
> raise) throws SQLException    {
>               double salary = 0;
>               while(rs.next())
>               {
>                       salary = rs.getDouble(3);
>                       rs.updateDouble(3, salary + raise);

Anda harus melakukan UPDATE dengan query update-nya MySQL.
Gunakan method executeUpdate dari Statement atau PreparedStatement.

>                       rs.updateRow(); }
>       }       
> }
> 
> Exception in thread "main" com.mysql.jdbc.NotUpdatable: 
> Result Set not updatable. This result set must come from a 
> statement that was created with a result set t
> ype of ResultSet.CONCUR_UPDATABLE, the query must select 
> only one table, and must select all primary keys from that 
> table. 
> dst.....

--
Donny Kurnia  --  13500021
Software Engineering Laboratory
Department of Informatics
Bandung Institute of Technology


-- 
Berhenti langganan: [EMAIL PROTECTED]
Arsip dan info: http://linux.or.id/milis.php

Kirim email ke