Subject Re: [Firebird-Java] Shoot store procedures in Firebird
Author Cristina Velasco
Hi,

Could you help me to address what do I have bad in my source code in Jbuilder?

The problem I have is the following:

I have to run an store procedure in Firebird every day according to a schedule. To do that I created a programmed task in Windows. Initially I put the class to generate a log file with today date. This one runs OK.

Now, I try to call the store procedure with the PreparedStatement method. My Firebird store procedure has the following parameters:

1. Today date

2. Today date minus 7 days

3. An integer, in this case number 1.

The source code is as well:

package procesosautomáticos;

import com.borland.dx.sql.dataset.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import javax.swing.*;
import com.borland.dx.dataset.*;
import com.borland.dx.sql.dataset.*;
import java.util.Date;
import java.util.*;
import java.awt.*;

**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class CalculaTallosAutomatico {
Database database1 = new Database();
QueryDataSet queryDataSetFechaHoy = new QueryDataSet();
Column column1 = new Column();
Column column2 = new Column();
JPanel jPanel1 = new JPanel();

public CalculaTallosAutomatico() {
PreparedStatement ct = database1.createPreparedStatement("execute procedure statistics_calcula_tallos ?, ?, ?");
FileOutputStream f;
try {

queryDataSetFechaHoy.open();
queryDataSetFechaHoy.refresh();
queryDataSetFechaHoy.first();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date fechaI = queryDataSetFechaHoy.getTimestamp("O_FECHA_DESDE");
java.util.Date fechaF = queryDataSetFechaHoy.getDate("O_FECHA_HASTA");
queryDataSetFechaHoy.close();
System.out.println("Fecha Inicial = " + fechaI);
System.out.println("Fecha Final = " + fechaF);

f = new FileOutputStream("c:\\BellaFarms\\LogCalculaTallos.txt"+ fechaI);
f.write(("Esta es la prueba del procedimiento " + fechaI + " " + fechaF + new Date()).getBytes());
f.close();


Date fechaActual = new Date();
String cadenaFecha = format.format(fechaActual);

ct.setTimestamp(1, new Timestamp(fechaActual.getTime()));

ct.setTimestamp(2, new Timestamp(fechaActual.getTime()));

ct.setInt(3,1);
ct.executeUpdate();

}
catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Error!");
}
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}


public static void main(String[] args) {
CalculaTallosAutomatico calculaTallosAutomatico1 = new CalculaTallosAutomatico();

}
private void jbInit() throws Exception {
jPanel1.setLayout(null);
column2.setColumnName("O_FECHA_HASTA");
column2.setDataType(com.borland.dx.dataset.Variant.TIMESTAMP);
column2.setTableName("STATISTICS_FECHA_HOY");
column2.setServerColumnName("O_FECHA_HASTA");
column2.setSqlType(93);
column1.setColumnName("O_FECHA_DESDE");
column1.setDataType(com.borland.dx.dataset.Variant.TIMESTAMP);
column1.setTableName("STATISTICS_FECHA_HOY");
column1.setServerColumnName("O_FECHA_DESDE");
column1.setSqlType(93);
queryDataSetFechaHoy.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from STATISTICS_FECHA_HOY", null, true, Load.ALL));
queryDataSetFechaHoy.setColumns(new Column[] {column1, column2});
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:firebirdsql:localhost/3050:c:\\Farms\\Data\\Mega.xab", "sysdba", "masterkey", false, "org.firebirdsql.jdbc.FBDriver"));}
}



I wrote some lines in rose color with the objective to identified if JBuilder can execute a Firebird´s store procedure through a queryDataSet, but when I run my class, JBuilder shows the following error message:

ee com.borland.dx.dataset.DataSetException error code: BASE+1

com.borland.dx.dataset.DataSetException: Missing or Bad query or database property settings. Could not execute query

at com.borland.dx.dataset.DataSetException.a(Unknown Source)

at com.borland.dx.dataset.DataSetException.badQueryProperties(Unknown Source)

at com.borland.dx.sql.dataset.QueryDataSet.refresh(Unknown Source)

at procesosautomáticos.CalculaTallosAutomatico.<init>(CalculaTallosAutomatico.java:37)

at procesosautomáticos.CalculaTallosAutomatico.main(CalculaTallosAutomatico.java:71)

Exception in thread "main"

I put the "PreparedStatement" method, and without to run the class the error message is:

unreported exception java.sql.SQLException; must be caught or declared to be thrown at line xx

This regarding the following code lines:

ct.setTimestamp(1, new Timestamp(fechaActual.getTime()));

ct.setTimestamp(2, new Timestamp(fechaActual.getTime()));

ct.setInt(3,1);
ct.executeUpdate();

Could you help me to identofied which are my mistakes... I´m beginner with JBuilder, so really I don´t know what is happening.

On the other hand, how can I get the system date with JBuilder in format MM/dd/yyyy, how can I get system date minus 7 days?

Thaks a lot,

Cristina



Roman Rokytskyy <rrokytskyy@...> wrote:
> Can I shoot store procedures on Firebird on daily basis according to
> an schedule?..

You have to code this yourself. There is no scheduler in Firebird.

Roman




Yahoo! Groups Links










---------------------------------
Win a castle for NYE with your mates and Yahoo! Messenger

[Non-text portions of this message have been removed]