Re: [問題] JSP比較資料庫檔案時間與系統時間
※ 引述《BILL0119 (BILL)》之銘言:
: 標題: Re: [問題] JSP比較資料庫檔案時間與系統時間
: 時間: Sat May 9 01:51:29 2009
:
: ※ 引述《BILL0119 (BILL)》之銘言:
: : 標題: [問題] JSP比較資料庫檔案時間與系統時間
: : 時間: Thu May 7 14:00:15 2009
: :
: : 目前有個JSP的問題想請板上的高手解答
: :
: : 我想抓出資料庫內的時間
: :
: : 並且比較目前系統時間 (只需要比較年份)
: :
: : 例如目前時間是2009年,資料庫內的時間是2003-7-20
: :
: : 我想要列出2003,2004,2005,2006,2007,2008,2009
: :
: : 但是資料庫內的時間格式是 年-月-日
: :
: : 目前時間
: : Calendar thisMonth=Calendar.getInstance();
: : String year=String.valueOf(thisMonth.get(Calendar.YEAR));
: :
: :
: : 資料庫內的時間
: : java.sql.Date dt = rs.getDate("DATE");
: : SimpleDateFormat sFmt = new SimpleDateFormat("yyyy");
: : String sDt = sFmt.format(dt);
: :
: :
: : 我要怎麼比較現在的系統時間
: :
: : 謝謝
: :
: :
: : --
: : ※ 發信站: 批踢踢實業坊(ptt.cc)
: : ◆ From: 114.42.160.15
: : ※ 編輯: BILL0119 來自: 114.42.160.15 (05/07 14:04)
: : ※ 編輯: BILL0119 來自: 114.42.160.15 (05/07 14:21)
: : 推 pm2001:從資料庫拉資料出來不然就下sql指令給資料庫算 05/07 14:24
:
: 不好意思,我是新手
: 想再請教一下,我下了SQL給資料庫運算後,要怎麼取運算後的數值啊??
: 假設說我下了 select count(no) as count from db.pt_info
: where year(current timestamp) - year(birthday) <35
: and sex IN('F')
: 想要取得小於35歲女性的人數
: 我看網路的資料都是用
: Connection conn = java.sql.DriverManager.getConnection
: (url,user,password);
:
: Statement stmt=conn.createStatement
: (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
:
: ResultSet rs = stmt.executeQuery("select count(no) ...........");
: 這表示他會回傳人數int給 ResultSet rs嗎? (但是這樣會有error訊息)
:
:
:
: : → GALINE:都是四位數年份字串的話....sdt.equals(year) ? 05/07 14:28
: : → GALINE:我自己是偏好資料庫內把時間存成字串,然後用substr做比對 05/07 14:29
: : → BILL0119:資料型態都是String,要怎麼運算呢? 05/07 15:25
: : 推 GALINE:用Integer.parseInt轉成數字再來算。不過最主要的原因是我 05/07 15:44
: : → GALINE:用不習慣原生的日期型態…[汗] 05/07 15:45
: : → TonyQ:其實可以直接下 year 給sql 去撈字串啊... 05/07 15:52
: : → BILL0119:了解,謝謝各位高手 05/07 16:03
:
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc)
: ◆ From: 114.42.161.22
: 推 TonyQ: as count count是保留字 , 寫成 as [count] or 換個名字 05/09 09:06
: → BILL0119:我直接在資料庫下這些指令是ok的,但是從JSP丟過去就錯了 05/09 11:26
: → BILL0119:指向 ResultSet rs = stmt.executeQuery(SQL) 有問題 05/09 11:28
: → BILL0119:但是我換成較簡單的指令都可以過 05/09 11:28
: → BILL0119:例如:select test from db2admin.test_data 05/09 11:29
: → BILL0119:真是讓我百思不得其解 =.= 05/09 11:30
: 推 GALINE:錯誤訊息是?單純數筆數我會用count(*) 05/09 13:27
: → TonyQ:那就把error message 拿出來看看. 05/09 18:31
訊息指出
HTTP Status 500
type Exception report
message
description The server encountered an internal error ()
that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException:
Exception in JSP: /Pages/AA_SQL_TEST.jsp:65
62:
63:
64: String sql = "select count(*) as count from db2admin.pt_info
where year(current timestamp) - year(birthday) <35 and sex IN('F')";
65: ResultSet rs = stmt.executeQuery(sql);
66:
67:
68:
這表示65行有問題?
這個SQL指令我在資料庫指令列下是ok的
我的環境是用apache-tomcat-5.5.27
eclipse java6-u13
db2資料庫
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.80.235
→
05/09 23:38, , 1F
05/09 23:38, 1F
→
05/09 23:38, , 2F
05/09 23:38, 2F
推
05/10 12:18, , 3F
05/10 12:18, 3F
→
05/10 12:19, , 4F
05/10 12:19, 4F
→
05/10 12:20, , 5F
05/10 12:20, 5F
→
05/10 12:20, , 6F
05/10 12:20, 6F
→
05/10 12:21, , 7F
05/10 12:21, 7F
→
05/10 12:22, , 8F
05/10 12:22, 8F
→
05/10 12:22, , 9F
05/10 12:22, 9F
→
05/10 14:34, , 10F
05/10 14:34, 10F
→
05/10 14:34, , 11F
05/10 14:34, 11F
→
05/10 14:49, , 12F
05/10 14:49, 12F
→
05/10 14:49, , 13F
05/10 14:49, 13F
→
05/10 14:50, , 14F
05/10 14:50, 14F
→
05/10 21:45, , 15F
05/10 21:45, 15F
討論串 (同標題文章)