日期:2014-05-16  浏览次数:20456 次

java类型和数据库字段类型的转换

在开发web应用中,针对不同的数据库类型,我们需要在我们的程序中做各种不同的转换<o:p></o:p>

数字―――>数字数字对象<o:p></o:p>

  1. int?i?=?169;? ??
  2. Integer?io?=?new?Integer(?i?);? ??
  3. i?=?io.intValue();? ??

数字―――>字符串

  1. String?s?=?String.valueOf(?value);?//?其中?value?为任意一种数字类型。? ??
  2. 或者 ??
  3. String?a=Integer.toString('整型'); ??
  4. ??

字符串―――>数字

  1. String?s?=?"169";? ??
  2. byte?b?=?Byte.parseByte(?s?);? ??
  3. int?i?=?Integer.parseInt(?s?);? ??
  4. Double?d?=?Double.parseDouble(?s?); ??
  5. ??

?

日期―――>字符串

<o:p></o:p>

?

?

  1. date1.toString()??

字符串―――>日期

将字符串类型的日期dateString转换为一个Date

  1. DateFormat?dateFormat?=?new?SimpleDateFormat("yyyy-MM-dd?kk:mm:ss.SSS",?Locale.ENGLISH);