Subject | Re: [Firebird-Java] numeric(15,2) and number of decimal places |
---|---|
Author | Steve Wiser |
Post date | 2007-02-28T14:11:46Z |
Ok, let me know if this works for you:
/*****
DB Create script:
(we ran it twice to create a dialect 1 and a dialect 3 database)
*****/
set sql dialect 1;
/* set sql dialect 3; */
create database 'server:/opt/firebird/databases/test.fdb' user 'SYSDBA'
password 'masterkey';
CREATE TABLE TEST (
MONEY NUMERIC(15,2)
);
insert into test(money) values(192.34);
/*****
Java Test
(once again it was run twice, once with dialect 1 and once with dialect
3 based on which db it was pointing to)
*****/
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class JaybirdTest{
private static final String jdbcUrl =
"jdbc:firebirdsql:server/3050:/opt/firebird/databases/test.fdb";
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Properties properties = new Properties();
properties.put("userName", "SYSDBA");
properties.put("password", "masterkey");
properties.put("sqlDialect", "3");
// properties.put("sqlDialect", "1");
Connection db = DriverManager.getConnection(jdbcUrl , properties);
Statement stmt = db.createStatement();
ResultSet rs = stmt.executeQuery("select money from test");
if (rs.next()) {
BigDecimal num = rs.getBigDecimal("money");
System.out.println("Numeric(15,2)");
System.out.println("Scale = " + num.scale());
System.out.println("toString() = " + num.toString());
}
rs.close();
stmt.close();
db.close();
}
}
/*****
Output of tests:
*****/
SQL Dialect 1 db
Scale = 45
toString() = 192.340000000000003410605131648480892181396484375
SQL Dialect 3 db
Scale = 2
toString() = 192.34
Thanks,
Steve
Roman Rokytskyy wrote:
/*****
DB Create script:
(we ran it twice to create a dialect 1 and a dialect 3 database)
*****/
set sql dialect 1;
/* set sql dialect 3; */
create database 'server:/opt/firebird/databases/test.fdb' user 'SYSDBA'
password 'masterkey';
CREATE TABLE TEST (
MONEY NUMERIC(15,2)
);
insert into test(money) values(192.34);
/*****
Java Test
(once again it was run twice, once with dialect 1 and once with dialect
3 based on which db it was pointing to)
*****/
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class JaybirdTest{
private static final String jdbcUrl =
"jdbc:firebirdsql:server/3050:/opt/firebird/databases/test.fdb";
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Properties properties = new Properties();
properties.put("userName", "SYSDBA");
properties.put("password", "masterkey");
properties.put("sqlDialect", "3");
// properties.put("sqlDialect", "1");
Connection db = DriverManager.getConnection(jdbcUrl , properties);
Statement stmt = db.createStatement();
ResultSet rs = stmt.executeQuery("select money from test");
if (rs.next()) {
BigDecimal num = rs.getBigDecimal("money");
System.out.println("Numeric(15,2)");
System.out.println("Scale = " + num.scale());
System.out.println("toString() = " + num.toString());
}
rs.close();
stmt.close();
db.close();
}
}
/*****
Output of tests:
*****/
SQL Dialect 1 db
>java -cp jaybird-full-2.1.0.jar;. JaybirdTestNumeric(15,2)
Scale = 45
toString() = 192.340000000000003410605131648480892181396484375
SQL Dialect 3 db
>java -cp jaybird-full-2.1.0.jar;. JaybirdTestNumeric(15,2)
Scale = 2
toString() = 192.34
Thanks,
Steve
Roman Rokytskyy wrote:
>
> Hi,
>
> > Thank you for the info! We made the change to specify that the
> > connection was to use Dialect 1, but we get the same problem. We are
> > preparing a set of test cases for you.
>
> Ok. Please provide also a database backup, so we have all pieces together.
>
> Thanks!
> Roman
>
>