您的位置:首页 > 产品设计 > UI/UE

Sybase datatype Issue

2012-09-14 20:55 302 查看
Sybase 数据类型

1. 首先我们来关注下Sybase官网对应的java数据类型映射关系

参照:http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.java/html/java/java138.htm

SQL datatype

Corresponding Java datatypes

Simply mappable

Object mappable

char/unichar

java.lang.String

nchar

java.lang.String

varchar/univarchar

java.lang.String

nvarchar

java.lang.String

text

java.lang.String

numeric

java.math.BigDecimal

decimal

java.math.BigDecimal

money

java.math.BigDecimal

smallmoney

java.math.BigDecimal

bit

boolean

Boolean

tinyint

byte

Integer

smallint

short

Integer

integer

int

Integer

bigint

java.math.BigInteger

unsigned smallint

int

Integer

unsigned int

long

Integer

unsigned bigint

java.math.BigInteger

real

float

Float

float

double

Double

double precision

double

Double

binary

byte[]

varbinary

byte[]

datetime

java.sql.Timestamp

smalldatetime

java.sql.Timestamp

date

java.sql.Date

time

java.sql.Time

2. 第一次在项目中使用sybase, 所以没有什么经验,所以查了上面的数据类型后开始项目

有这样一个表:

create table ***(

TASKID numeric(10,0)

TASKNAME varchar(255)

FILESIZE numeric(10,2)

)

由上面的类型表可以见到

numeric 对应 java.math.BigDecimal

所以在执行sql为其设置参数代码如下:

setIntArgument(1, taskId);

setStringArgument(2,filepath);

setDecimalArgument(3, new BigDecimal(fileSize/1000d));

本以为可以顺利执行并返回结果,可是往往事与愿违,没有任何 错误以及异常。苦想很久,最后直接debug看到:

ClassNotFoundException:

arg0: com.sybase.jdbc3.tds.SybBigDecimal 但是去Sybase提供的驱动包中很显然可以找到,神奇之处。最后果断换掉,

利用

setDoubleArgument(3, fileSize/1000d); 通过,真是好玩啊

类似的问题还有:

DateTime - Timestamp

ClassnotFoundException:

com.sybase.jdbc3.jdbc.ErrorMessage

com.sybase.jdbc3.tds.TdsDateTime

Syabse的开发人员就是牛啊,居然都不用debug就能开发出这样的数据库来,真是厉害,程序员真是伤不起啊。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: