data(二)
今天做Date的时候发现一个简单的在jsp视图中插入代码时候容易犯的错误
申明变量和方法的时候就要用
<%!
%>
不能用s
<%
%>
因为这个是语句控制的
先导入
<%@ page import="java.sql.Timestamp"%>
public String getNowTime()
{
String nowTime = new Timestamp(new Date().getTime()).toString();
return nowTime;
}
先导入
<%@ page import="java.util.*" %>
java.util.Date date=new java.util.Date();
Timestamp nousedate_result = new Timestamp(date.getTime()); System.out.println(nousedate_result);
create table deposit
( account char(10)references account(accountno),
depositamount char(10),
date timestamp
)
在个deposit 插入值是说date的用法有错误,请问怎么才能正确使用呢,得到当前插入操作的时间呢
insert into tm values(TO_TIMESTAMP('2006-12-01 12:12:09.123456789', 'YYYY-MM-DD HH24:MI:SS.FF'));
sql2000中的是:
create table deposit
( account char(10)references account(accountno),
depositamount char(10),
date datetime DEFAULT GETDATE()
)
mysql中的是:
CREATE TABLE `test`.`myDate` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`mydate` DATETIME NOT NULL default '2008-8-8',
PRIMARY KEY(`id`)
)
可以这么插入,因为有默认值了
insert into mydate(id)values(1);
import java.sql.Date;
public class Category {
private Integer categoryId;
private String categoryName;
private Date createdDate;
不知道为什么这个写法居然有问题
<%@ page language="java" pageEncoding="GB2312"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'insertDate.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%!
Date theDate=new Date();
Date getDate() {System.out.println("In getDate() method");return theDate; }
%>
<%
try {
myData.DataStore ds= myData.DataStore.getInstance();
String sql="select * from user";
ResultSet rs=null;
rs=ds.read(sql);
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
</body>
</html>
DROP DATABASE IF EXISTS ttt;
CREATE DATABASE ttt;
USE ttt;
DROP TABLE IF EXISTS t_admin;
CREATE TABLE t_admin(
adName VARCHAR(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARACTER SET UTF8 ;
浙公网安备 33010602011771号