JDBC 关于Date格式
package test;
import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SqlDate {
/**
* @param args
* @throws SQLException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// TODO Auto-generated method stub
create("name2",new Date(),1000.9f);
System.out.println(getData(1));
}
static void create(String name,Date birthday,float money) throws SQLException {
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
//3,Statement用于“运送”sql语句和sql语句执行结果
String sql = "insert into user(name,birthday,money) values (?,?,?)";
st = conn.prepareStatement(sql);
st.setString(1, name);
st.setDate(2, new java.sql.Date(birthday.getTime()));//将util的Date转换为sql的Date
st.setFloat(3, money);
//4,执行sql
int count = st.executeUpdate();
System.out.println(count);
} finally {
JdbcUtils.free(rs, st, conn);
}
}
private static Date getData(int id) throws ClassNotFoundException, SQLException {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
Date bithday = null;
try {
conn = JdbcUtils.getConnection();
st = conn.createStatement();
rs = st.executeQuery("select birthday from user where id = "+id);
while(rs.next()) {
bithday = rs.getDate("birthday");
}
} finally {
JdbcUtils.free(rs, st, conn);
}
return bithday;
}
}
JDBC 关于Date格式的更多相关文章
- JSP页面用EL表达式 输出date格式
JSP页面用EL表达式 输出date格式 1.头上引入标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix ...
- js 将php生成的time()类型时间戳转化成具体date格式的日期
需求: 将首页显示的int类型的时间转化为date类型的时间格式: QuestionModel获取到question列表数据时,包括question['pub_time'],在显示 ...
- mybatis从数据库中取到的date格式不是yyyy-MM-dd HH:mm:ss
问题:sqlserver中的存储时间格式为date,pojo的时间属性也是date,直接mybatis取出的时间格式是带英语的那种,不满足客户要求. 解决:将pojo的时间属性改为string类型,在 ...
- 使用 JSON.parse 反序列化 ISO 格式的日期字符串, 将返回Date格式对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【数据库_Mysql】JAVA-数据库Date格式在前台JSP页面的获取
问题: 数据库保存的为date格式的日期 在前台JSP页面显示的为一串数字1487897 解决办法: 数据库表中字段对应的实体对象属性的get方法上添加一行代码 页面即可正常显示
- Java中String与Date格式之间的转换
转自:https://blog.csdn.net/angus_17/article/details/7656631 经常遇到string和date之间的转换,把相关的内容总结在这里吧: 1.strin ...
- 字符串时间转Date格式
/** * 字符串时间格式转 Date 格式 * @param strDate * @return */ public static Date getDateTimeByStringTime(Stri ...
- 字符串格式时间转Date格式
/** * 字符串时间格式转 Date 格式 * @param strDate * @return */ public static Date getDateTimeByStringTime(Stri ...
- 修改git log中的Date格式
默认的git log查看日志显示的格式如下: Date: Thu Aug 16 17:44:32 2018 +0800 说实话,真不太喜欢这种日期格式还是换成数值比较舒服一点.git bash中使 ...
随机推荐
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan
1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec Memory Limit: 64 MB Description The N (2 & ...
- Codechef APRIL14 ANUCBC Cards, bags and coins 背包DP变形
题目大意 有n个数字,选出一个子集,有q个询问,求子集和模m等于0的方案数%1000000009.(n <= 100000,m <= 100,q <= 30) 假设数据很小,我们完全 ...
- WebSQL的基本使用过程
1.创建或打开数据库(openDatabase) var db = openDatabase('dbname', '1.0', 'discription', 2 * 1024); // 目前测试只有C ...
- 权限验证AuthorizeAttribute
/// <summary> /// 权限验证属性. /// </summary> public class AuthorizeExAttribute : AuthorizeAt ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题
Tavas and Karafs Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...
- 【弱省胡策】Round #0 Flower Dance DP
Flower Dance Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://162.105.80.126/contest/%E3%80%90%E ...
- 套题:Codeforces Round #194 (Div. 1) (2/5)
A. Secrets http://www.cnblogs.com/qscqesze/p/4528529.html B. Chips http://www.cnblogs.com/qscqesze/p ...
- linux下使用free命令查看实际内存占用(可用内存)
转:http://blog.is36.com/linux_free_command_for_memory/ linux下在终端环境下可以使用free命令看到系统实际使用内存的情况,一般用free -m ...
- End of Life check fails with NullPointerException
Checks if the running version of JIRA is approaching, or has reached End of Life. Details Type: Bug ...