updating a maximum of 2 records

2015-02-08 Thread Bob M
Hi

I am trying to code for the ability to update either two records (the two
records which have the latest date & time) or just one (the record which has
the latest date & time) for the profit field
If two_time is TRUE, then two records are requiring updating, otherwise just
the one record
The records which need updating have 999.99 in the profit field initially
There are x+2 records in the database
At the moment, no updating is taking place - any idea why ?


// if we have two records to update
// i.e. the penultimate record which was closed at the last clock-in point
// and the ultimate record which was opened at the same time and has since
closed
if ((two_time) && (!initialize) && (myCanTrade) && (myCurrPositionValue >0))
{
// retrieve the last two records
rs = s.executeQuery("SELECT * FROM TABLE ORDER BY Trading_Date ASC,"
+ " Trading_Time ASC OFFSET x ROWS FETCH NEXT 2 ROWS ONLY");
rs.next();
String Date2 = rs.getString("Trading_Date");
int Time2 = rs.getInt("Trading_Time");
s.setCursorName("MYCURSOR");
rs = s.executeQuery("SELECT * FROM TABLE WHERE Date = " + Date2 + " AND Time
= " + Time2 + " FOR UPDATE");
rs.next();
conn.prepareStatement("UPDATE TABLE SET PROFIT_LOSS = prev_profit WHERE
CURRENT OF MYCURSOR").executeUpdate();
prev_profit = 0;
//move on to the last record
rs.next();
String Date3 = rs.getString("Trading_Date");
int Time3 = rs.getInt("Trading_Time");
s.setCursorName("MYCURSOR");
rs = s.executeQuery("SELECT * FROM TABLE WHERE Date = " + Date3 + " AND Time
= " + Time3 + " FOR UPDATE");
rs.next();
conn.prepareStatement("UPDATE TABLE SET PROFIT_LOSS = profit WHERE CURRENT
OF MYCURSOR").executeUpdate();
two_time =false;
} // end of updating the last two records
 else {
// else, if we have just the one record to update 
// retrieve and output date and time of the latest record from the table
// providing this is not the first trade and we are about to open a new
trade !
if ((!initialize) && (myCanTrade) && (myCurrPositionValue >0)) {
psUpdate = conn.prepareStatement("UPDATE TABLE SET PROFIT_LOSS=? WHERE
PROFIT_LOSS = 999.99");
statements.add(psUpdate);
psUpdate.setDouble(1, profit);
psUpdate.executeUpdate();
}
} // end of updating latest record
*

Bob M




--
View this message in context: 
http://apache-database.10148.n7.nabble.com/updating-a-maximum-of-2-records-tp143764.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: error 08001 local database

2015-02-08 Thread Ignacio Yuste Lopez
hi,

I use the first way. I installed java using directly but derby with the
repository of Ubuntu.


Ignacio Yuste López

Camilo Jose Cela 8 Portal 2 3º puerta 6
Las Rozas de Madrid, 28232
Madrid

On Sun, Feb 8, 2015 at 5:36 PM, Bryan Pendleton 
wrote:

> On 2/7/2015 2:46 AM, Ignacio Yuste Lopez wrote:
>
>>   ij> connect 'jdbc:derby:MyDbTest;create=true';
>> ERROR 08001: No suitable driver found for jdbc:derby:MyDbTest;create=true
>>
>>
> Which of the 3 ways of running ij that are documented here
> http://db.apache.org/derby/docs/10.11/getstart/tgsrunningij.html
> did you use?
>
>  I copy the exit of sysinfo if somebody could show me the problem
>>
>> Versión de Java: 1.8.0_25
>>
>
> This is very new.
>
>  [/usr/share/javadb/lib/derby.jar] 10.3.2.1 - (599110)
>>
>
> This is very old.
>
> Why did you select such an old version of Derby?
>
> Does your problem persist if you use Derby 10.11?
>
> thanks,
>
> bryan
>
>


Re: error 08001 local database

2015-02-08 Thread Bryan Pendleton

On 2/7/2015 2:46 AM, Ignacio Yuste Lopez wrote:

  ij> connect 'jdbc:derby:MyDbTest;create=true';
ERROR 08001: No suitable driver found for jdbc:derby:MyDbTest;create=true



Which of the 3 ways of running ij that are documented here
http://db.apache.org/derby/docs/10.11/getstart/tgsrunningij.html
did you use?


I copy the exit of sysinfo if somebody could show me the problem

Versión de Java: 1.8.0_25


This is very new.


[/usr/share/javadb/lib/derby.jar] 10.3.2.1 - (599110)


This is very old.

Why did you select such an old version of Derby?

Does your problem persist if you use Derby 10.11?

thanks,

bryan



error 08001 local database

2015-02-08 Thread Ignacio Yuste Lopez
Hi,

I just install derby on my laptop and I'm trying to create a new database.
The first time I try to write the command in ij but error 08001 has appear.
The second time I just copy and paste the command from the tutorial page
and I had have the same result.

 ij> connect 'jdbc:derby:MyDbTest;create=true';
ERROR 08001: No suitable driver found for jdbc:derby:MyDbTest;create=true

After the installation I've add this to .bashrc

export PATH=$PATH:/usr/share/javadb/bin/
export DERBY_HOME=/usr/share/javadb


I copy the exit of sysinfo if somebody could show me the problem

- Información de Java 
Versión de Java: 1.8.0_25
Proveedor de Java:   Oracle Corporation
Inicio Java: /opt/jdk/jdk1.8.0_25/jre
Classpath de Java:
/usr/share/javadb/lib/derby.jar:/usr/share/javadb/lib/derbynet.jar:/usr/share/javadb/lib/derbytools.jar:/usr/share/javadb/lib/derbyclient.jar
Nombre del SO:   Linux
Arquitectura del SO: amd64
Versión del SO:  3.13.0-45-generic
Nombre usuario Java: portatil
Dir. inicial usuario:/home/portatil
Dir. usuario:/home/portatil/Documentos/Desarrollo/DB
java.specification.name: Java Platform API Specification
java.specification.version: 1.8
- Información de Derby 
JRE - JDBC: Java SE 6 - JDBC 4.0
[/usr/share/javadb/lib/derby.jar] 10.3.2.1 - (599110)
[/usr/share/javadb/lib/derbytools.jar] 10.3.2.1 - (599110)
[/usr/share/javadb/lib/derbynet.jar] 10.3.2.1 - (599110)
[/usr/share/javadb/lib/derbyclient.jar] 10.3.2.1 - (599110)
--
-- Información de entorno local --
Entorno local actual:  [español/España [es_ES]]
Se encontró soporte para el entorno local: [cs]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [de_DE]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [es]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [fr]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [hu]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [it]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [ja_JP]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [ko_KR]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [pl]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [pt_BR]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [ru]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [zh_CN]
 versión: 10.3.2.1 - (599110)
Se encontró soporte para el entorno local: [zh_TW]
 versión: 10.3.2.1 - (599110)
--