You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Legolas Woodland <le...@gmail.com> on 2005/09/15 09:28:13 UTC

Update took too long and at last it does not do anything

Hi
I used derby for a project (i have latest version)
When i update a record from my java code its dies and do nothing where i 
think my codes are true,
here is the code.
 String uStr = "update EMPLOYEE set FIRSTNME=?,MIDINIT=? where EMPNO=?";
pstmt.setString(1, getFirstName());
pstmt.setString(2, getMidName());
pstmt.setString(3, getLastName());
pstmt.executeUpdate()
  where the connection comes from a connection pool,
I test the connection by inserting data and data insert correctly.
can some one help me pleas?

Re: Update took too long and at last it does not do anything

Posted by Kristian Waagan <Kr...@Sun.COM>.
Hello,

I feel the need to clarify a few points:

  * You do prepare your statement?
    I can't see the prepare call (i.e. conn.prepareStatement(uStr)).

  * I am not sure your SQL does what you intend it to do, but as I do not
    have your database schema, it is hard to tell for sure. Based on the
    names you are using, I would guess the field EMPNO is a number
    (integer?), but you are supplying a last name (string).
    Apart from that, the SQL statement looks correct.

This is only guessing, but the code could be like this:

 >>>> CODE START >>>>
String uStr = "update EMPLOYEE set FIRSTNAME=?,MIDINIT=?,LASTNAME=? 
where EMPNO=?";
PreparedStatement pstmt = conn.prepareStatement(uStr);

// Some kind of loop here, iterating though all tuples to be updated.
	pstmt.setString(1, getFirstName());
	pstmt.setString(2, getMidName());
	pstmt.setString(3, getLastName());
	pstmt.setInt(4, getEmpNo());
	pstmt.executeUpdate()

// Don't forget to commit!
conn.commit();
<<<< CODE END <<<<

Using prepared statements in Derby is very important to get high 
performance. Autocommit mode must also be turned off, and then one must 
not forget to commit :)

If my attempt at helping you is off, please provide error messages or 
more information, and we will have another try at it!




Regards,
--
Kristian


Legolas Woodland wrote:
> Hi
> I used derby for a project (i have latest version)
> When i update a record from my java code its dies and do nothing where i 
> think my codes are true,
> here is the code.
>  
> String uStr = "update EMPLOYEE set FIRSTNME=?,MIDINIT=? where EMPNO=?";
> pstmt.setString(1, getFirstName());
>                 pstmt.setString(2, getMidName());
>                 pstmt.setString(3, getLastName());
> pstmt.executeUpdate()
>  
>  
> where the connection comes from a connection pool,
> I test the connection by inserting data and data insert correctly.
> can some one help me pleas?
>  
>  

Re: Update took too long and at last it does not do anything

Posted by Knut Anders Hatlen <Kn...@sun.com>.
Legolas Woodland <le...@gmail.com> writes:

> Hi
> I used derby for a project (i have latest version)
> When i update a record from my java code its dies and do nothing where i think my codes are true,
> here is the code.
>  
> String uStr = "update EMPLOYEE set FIRSTNME=?,MIDINIT=? where EMPNO=?";
> pstmt.setString(1, getFirstName());
>                 pstmt.setString(2, getMidName());
>                 pstmt.setString(3, getLastName());
> pstmt.executeUpdate()
>
> where the connection comes from a connection pool,
> I test the connection by inserting data and data insert correctly.
> can some one help me pleas?

What error messages are you seeing when your application dies?

-- 
Knut Anders