Home > Database > Mysql Tutorial > MYSQL JDBC 数据类型_MySQL

MYSQL JDBC 数据类型_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:51:39
Original
1023 people have browsed it

Reference: 《JDBC setObject非主流性能报告》[1]

MySQL与JAVA里面的时间类型对应

MYSQL时间类型 JAVA对应的时间类型
date java.sql.Date
Year ava.sql.Date
Datetime java.sql.Timestamp
Timestamp java.sql.Timestamp
Time java.sql.Time

附上一段代码

<pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #fbfbfb">Calendar cal=Calendar.getInstance();
Copy after login
Timestamp now=new Timestamp(cal.getTime().getTime());
Copy after login

然后用JDBC插入的时候要用prepareStatement.setTimestamp()

再说说prepareStatement,有一堆setInt,setString,setDate什么的。其实还有一个非常强大的stObject(),能自动转换匹配类型,而且性能不差,这就延伸出了好多种用法了吧,其实我最初仅仅是为了用来向preparedStatement中插入null的 –_-!  另外如果把preparedStatement中的占位符留空,将会写成** NOT SPECIFIED **,不知道会不会自动弄成null呢

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template