设为首页 加入收藏

TOP

实现通用的PreparedStatement更新记录的方法(六)
2014-11-24 12:04:54 】 浏览:1772
Tags:实现 通用 PreparedStatement 新记录 方法
ntinue;
}
//特殊类型,非常用,置后
if (className.equals("com.sybase.jdbc2.tds.SybTimestamp") || className.toLowerCase().indexOf("timestamp") > 0) {
if ((_c.equals("java.lang.String")) && (!"".equals(((String) v).trim()))) {
pstmt.setTimestamp(i + 1, java.sql.Timestamp.valueOf((String) v));
} else {
pstmt.setTimestamp(i + 1, (java.sql.Timestamp) v);
}
continue;
}
//概略匹配
if (className.toLowerCase().indexOf("date") > 0) {
if ((_c.equals("java.lang.String")) && (!"".equals(((String) v).trim()))) {
pstmt.setDate(i + 1, java.sql.Date.valueOf((String) v));
} else {
pstmt.setDate(i + 1, new java.sql.Date(((java.util.Date) v).getTime()));
}
continue;
}
if (className.toLowerCase().indexOf("time") > 0) {
if ((_c.equals("java.lang.String")) && (!"".equals(((String) v).trim()))) {
pstmt.setTime(i + 1, java.sql.Time.valueOf((String) v));
} else {
pstmt.setTime(i + 1, (java.sql.Time) v);
}
continue;
}
if (_c.equals("java.io.FileInputStream")) {
//调用如:FileInputStream in = new FileInputStream("D:\\test.jpg");的结果
pstmt.setBinaryStream(i + 1, (FileInputStream) v, ((FileInputStream) v).available());
continue;
}//java.io.FileInputStream
//其它特殊类型,非常用,置后,更多的setXXX方法详见《年鉴》p700
}
}
}
num = num + pstmt.executeUpdate();
}
} catch (java.lang.ClassCastException ex) {
throw new SQLException("java.lang.ClassCastException: " + ex.getMessage(), ex.getCause());
} catch (NumberFormatException ex) {
throw new SQLException("NumberFormatException: " + ex.getMessage(), ex.getCause());
} catch (IOException ex) { www.2cto.com
throw new SQLException("IOException: " + ex.getMessage(), ex.getCause());
} finally {
pstmt.close();
}
return num;
}
通配符对应的赋值方法参见“SQL数据类型与Java类的对应关系”一文
首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇黑马程序员_常见java问题小计 下一篇JSF,第二代Java页面技术

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目