Last active
June 29, 2017 15:49
-
-
Save pei0804/5db3975cb98ad23f5c9ffa70ee0d2b03 to your computer and use it in GitHub Desktop.
MA42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.beans.sample; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.HashMap; | |
public class MyCalendar01 { | |
/** | |
* NEN | |
* 年 | |
*/ | |
public static final int NEN = 0; | |
/** | |
* TSUKI | |
* 月 | |
*/ | |
public static final int TSUKI = 1; | |
/** | |
* HI | |
* 日 | |
*/ | |
public static final int HI = 2; | |
private Calendar cal; | |
private String[] weekNameJa = { "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日" }; | |
private String[] weekNameEn = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; | |
private static final int MILLIS_OF_DAY = 1000 * 60 * 60 * 24; | |
private static final HashMap<Integer, Integer> FIELD = new HashMap<Integer, Integer>() { | |
{put(NEN, Calendar.YEAR);} | |
{put(TSUKI, Calendar.MONTH);} | |
{put(HI, Calendar.DATE);} | |
}; | |
/** | |
* MyCalendar01 | |
* コンストラクタ | |
*/ | |
public MyCalendar01() { | |
this.cal = Calendar.getInstance(); | |
} | |
/** | |
* MyCalendar01 | |
* コンストラクタ | |
*/ | |
public MyCalendar01(int intYear, int intMonth, int intDay) { | |
this.cal = Calendar.getInstance(); | |
this.cal.set(intYear, intMonth - 1, intDay); | |
} | |
/** | |
* MyCalendar01 | |
* コンストラクタ | |
*/ | |
public MyCalendar01(String strYear, String strMonth, String strDay) { | |
this(Integer.parseInt(strYear), Integer.parseInt(strMonth) - 1, Integer.parseInt(strDay)); | |
} | |
/** | |
* setYear | |
* 引数として年をセットする | |
*/ | |
public void setYear(int intYear) { | |
this.cal.set(Calendar.YEAR, intYear); | |
} | |
/** | |
* setYear | |
* 引数として年をセットする | |
*/ | |
public void setYear(String strYear) { | |
this.cal.set(Calendar.YEAR, Integer.parseInt(strYear)); | |
} | |
/** | |
* setMonth | |
* 引数として月をセットする | |
*/ | |
public void setMonth(int intMonth) { | |
this.cal.set(Calendar.MONTH, intMonth - 1); | |
} | |
/** | |
* setMonth | |
* 引数として月をセットする | |
*/ | |
public void setMonth(String strMonth) { | |
this.cal.set(Calendar.MONTH, Integer.parseInt(strMonth) - 1); | |
} | |
/** | |
* setDay | |
* 引数として日をセットする | |
*/ | |
public void setDay(int intDay) { | |
this.cal.set(Calendar.DATE, intDay); | |
} | |
/** | |
* setDay | |
* 引数として日をセットする | |
*/ | |
public void setDay(String strDay) { | |
this.cal.set(Calendar.DATE, Integer.parseInt(strDay)); | |
} | |
/** | |
* set | |
* 年月日をセットする | |
*/ | |
public void set(int intYear, int intMonth, int intDay) { | |
this.cal.set(intYear, intMonth - 1, intDay); | |
} | |
/** | |
* set | |
* 年月日をセットする | |
*/ | |
public void set(String strYear, String strMonth, String strDay) { | |
this.cal.set(Integer.parseInt(strYear), Integer.parseInt(strMonth) - 1, Integer.parseInt(strDay)); | |
} | |
/** | |
* set | |
* 定数で指定された年月日に値をセット | |
*/ | |
public void set(int intTarget, int intValue) { | |
if (intTarget == MyCalendar01.TSUKI) { | |
intValue--; | |
} | |
this.cal.set(MyCalendar01.FIELD.get(intTarget), intValue); | |
} | |
/** | |
* set | |
* 定数で指定された年月日に値をセット | |
*/ | |
public void set(int intTarget, String strValue) { | |
int intVal = Integer.parseInt(strValue); | |
if (intTarget == MyCalendar01.TSUKI) { | |
intVal--; | |
} | |
this.cal.set(MyCalendar01.FIELD.get(intTarget), intVal); | |
} | |
/** | |
* add | |
* 引数の値を加算する | |
*/ | |
public void add(int intDay) { | |
this.cal.add(MyCalendar01.FIELD.get(MyCalendar01.HI), intDay); | |
} | |
/** | |
* add | |
* 引数の値を加算する | |
*/ | |
public void add(String strDay) { | |
this.cal.add(MyCalendar01.FIELD.get(MyCalendar01.HI), Integer.parseInt(strDay)); | |
} | |
/** | |
* add | |
* 定数で指定された年月日に値を加算する | |
*/ | |
public void add(int target, int value) { | |
this.cal.add(MyCalendar01.FIELD.get(target), value); | |
} | |
/** | |
* add | |
* 定数で指定された年月日に値を加算する | |
*/ | |
public void add(int target, String value) { | |
this.cal.add(MyCalendar01.FIELD.get(target), Integer.parseInt(value)); | |
} | |
/** | |
* difference | |
* 引数の年月日との日数差を返す | |
*/ | |
public long difference(int intYear, int intMonth, int intDay) { | |
Calendar dateDiff = Calendar.getInstance(); | |
dateDiff.set(intYear, intMonth - 1, intDay); | |
return getDateDiff(this.cal, dateDiff); | |
} | |
/** | |
* difference | |
* 引数の年月日との日数差を返す | |
*/ | |
public long difference(String strYear, String strMonth, String strDay) { | |
Calendar dateDiff = Calendar.getInstance(); | |
dateDiff.set(Integer.parseInt(strYear), Integer.parseInt(strMonth) - 1, Integer.parseInt(strDay)); | |
return getDateDiff(this.cal, dateDiff); | |
} | |
private long getDateDiff(Calendar targetDate ,Calendar diffDate) { | |
long diffTime = targetDate.getTimeInMillis() - diffDate.getTimeInMillis(); | |
return Math.abs(diffTime / MyCalendar01.MILLIS_OF_DAY); | |
} | |
/** | |
* getYear | |
* 年をStringで返す | |
*/ | |
public String getYear() { | |
return String.valueOf(this.cal.get(Calendar.YEAR)); | |
} | |
/** | |
* getMonth | |
* 月をStringで返す(人間が扱う値) | |
*/ | |
public String getMonth() { | |
return String.valueOf(cal.get(Calendar.MONTH) + 1); | |
} | |
/** | |
* getDay | |
* 日をStringで返す | |
*/ | |
public String getDay() { | |
return String.valueOf(cal.get(Calendar.DATE)); | |
} | |
/** | |
* getJapaneseFormat | |
* 「yyyy年MM月dd日」を返す | |
*/ | |
public String getJapaneseFormat() { | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); | |
return sdf.format(this.cal.getTime()); | |
} | |
/** | |
* getJapaneseWeek | |
* 設定された日付の曜日を日〜土で返す | |
*/ | |
public String getJapaneseWeek() { | |
return this.weekNameJa[cal.get(Calendar.DAY_OF_WEEK) - 1]; | |
} | |
/** | |
* getSimpleFormat | |
* 「yyyy/MM/dd」を返す | |
*/ | |
public String getSimpleFormat() { | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); | |
return sdf.format(this.cal.getTime()); | |
} | |
/** | |
* getEnglishWeek | |
* 指定された曜日の英語表記を返す(3文字) | |
*/ | |
public String getEnglishWeek(Calendar cal) { | |
return this.weekNameEn[cal.get(Calendar.DAY_OF_WEEK) - 1]; | |
} | |
/** | |
* getJapaneseMonth | |
* 設定された月を【9月】の形で返す。 | |
*/ | |
public String getJapaneseMonth() { | |
return MyCalendarStatic01.getMonthString(this.cal); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.beans.sample; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
public class MyCalendarStatic01 { | |
/* | |
* getMonthString | |
* 指定された月を文字列で返す。例:6月 | |
*/ | |
static String getMonthString(Calendar cal) { | |
SimpleDateFormat sdf = new SimpleDateFormat("MM月"); | |
return sdf.format(cal.getTime()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.beans.sample; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.HashMap; | |
public class MyCalendar11 extends MyCalendar01 { | |
/** | |
* JI | |
* 時間 | |
*/ | |
public static final int JI = 3; | |
/** | |
* FUN | |
* 時間 | |
*/ | |
public static final int FUN = 4; | |
/** | |
* BYO | |
* 秒 | |
*/ | |
public static final int BYO = 5; | |
protected static final HashMap<Integer, Integer> FIELD = new HashMap<Integer, Integer>() { | |
{put(NEN, Calendar.YEAR);} | |
{put(TSUKI, Calendar.MONTH);} | |
{put(HI, Calendar.DATE);} | |
{put(JI, Calendar.HOUR_OF_DAY);} | |
{put(FUN, Calendar.MINUTE);} | |
{put(BYO, Calendar.SECOND);} | |
}; | |
/** | |
* MyCalendar11 | |
* 現在日の取得。親クラスのコンストラクタ実行 | |
*/ | |
public MyCalendar11() { | |
super(); | |
} | |
/** | |
* MyCalendar11 | |
* 指定された日(int型)を親フィールドへセット | |
*/ | |
public MyCalendar11(int intYear, int intMonth, int intDay) { | |
super(intYear, intMonth - 1, intDay); | |
} | |
/** | |
* MyCalendar11 | |
* 指定された日(int型)を親フィールドへセット | |
*/ | |
public MyCalendar11(String strYear, String strMonth, String strDay) { | |
super(strYear, strMonth, strDay); | |
} | |
/** | |
* MyCalendar11 | |
* 指定された日(String型)を親フィールドへセット | |
*/ | |
public MyCalendar11(int intYear, int intMonth, int intDay, int intHour, int intMinute, int intSecond) { | |
super.cal.set(intYear, intMonth - 1, intDay, intHour, intMinute, intSecond); | |
} | |
/** | |
* MyCalendar11 | |
* 親コンストラクタを呼び出す | |
*/ | |
public MyCalendar11(String strYear, String strMonth, String strDay, String strHour, String strMinute, String strSecond) { | |
this( | |
Integer.parseInt(strYear), | |
Integer.parseInt(strMonth), | |
Integer.parseInt(strDay), | |
Integer.parseInt(strHour), | |
Integer.parseInt(strMinute), | |
Integer.parseInt(strSecond) | |
); | |
} | |
/** | |
* set | |
* 定数で指定された日時に値をセット | |
*/ | |
@Override | |
public void set(int intTarget, int intValue) { | |
if (intTarget == MyCalendar11.TSUKI) { | |
intValue--; | |
} | |
super.cal.set(MyCalendar11.FIELD.get(intTarget), intValue); | |
} | |
/** | |
* set | |
* 定数で指定された日時に値をセット | |
*/ | |
@Override | |
public void set(int intTarget, String strValue) { | |
int intVal = Integer.parseInt(strValue); | |
if (intTarget == MyCalendar11.TSUKI) { | |
intVal--; | |
} | |
super.cal.set(MyCalendar11.FIELD.get(intTarget), intVal); | |
} | |
/** | |
* add | |
* 定数で指定された日時に値を加算する | |
*/ | |
@Override | |
public void add(int intTarget, int intValue) { | |
super.cal.add(MyCalendar11.FIELD.get(intTarget), intValue); | |
} | |
/** | |
* add | |
* 定数で指定された日時に値を加算する | |
*/ | |
@Override | |
public void add(int intTarget, String strValue) { | |
super.cal.add(MyCalendar11.FIELD.get(intTarget), Integer.parseInt(strValue)); | |
} | |
/** | |
* getJapaneseFormat | |
* 「yyyy年MM月dd日 hh時mm分ss秒」を返す | |
*/ | |
@Override | |
public String getJapaneseFormat() { | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh時mm分ss秒"); | |
return sdf.format(super.cal.getTime()); | |
} | |
/** | |
* getSimpleFormat | |
* 「yyyy/MM/dd hh:mm:ss」を返す | |
*/ | |
@Override | |
public String getSimpleFormat() { | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); | |
return sdf.format(super.cal.getTime()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@page import="my.beans.db.MyDBAccess01"%> | |
<%@ page language="java" contentType="text/html; charset=UTF-8" | |
pageEncoding="UTF-8"%> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>Insert title here</title> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<th>GAKUSEI</th> | |
<th>KURASU</th> | |
<th>SHUSSEKI</th> | |
<th>SHIMEI</th> | |
<th>NENREI</th> | |
</tr> | |
<% | |
MyDBAccess01 mda = (MyDBAccess01)request.getAttribute("myVal"); | |
String[][] strDBVal = mda.getResult(); | |
for (int i = 0; i < strDBVal.length; i++){ | |
%> | |
<tr> | |
<td><%=strDBVal[i][0] %></td> | |
<td><%=strDBVal[i][1] %></td> | |
<td><%=strDBVal[i][2] %></td> | |
<td><%=strDBVal[i][3] %></td> | |
<td><%=strDBVal[i][4] %></td> | |
</tr> | |
<% | |
} | |
%> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.beans.db; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
public class MyDBAccess01 { | |
protected Connection cn = null; | |
protected Statement st = null; | |
protected ResultSet rs = null; | |
protected String[][] strArray = new String[5][5]; | |
public MyDBAccess01() { | |
} | |
public void select() { | |
try { | |
this.rs = this.st.executeQuery("SELECT * FROM t01_gakusei"); | |
int i = 0; | |
while(this.rs.next()) { | |
this.strArray[i][0] = this.rs.getString("GAKUSEKI"); | |
this.strArray[i][1] = this.rs.getString("KURASU"); | |
this.strArray[i][2] = this.rs.getString("SHUSSEKI"); | |
this.strArray[i][3] = this.rs.getString("SHIMEI"); | |
this.strArray[i][4] = this.rs.getString("NENREI"); | |
i++; | |
} | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
public String[][] getResult() { | |
return strArray; | |
} | |
public void open() { | |
try { | |
Class.forName("com.mysql.jdbc.Driver"); | |
this.cn = DriverManager.getConnection("jdbc:mysql://localhost/ma4205db02", "mysqluser", "mysqlpassword"); | |
this.st = this.cn.createStatement(); | |
} catch (ClassNotFoundException e) { | |
System.out.println(e.getMessage()); | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
public void close() { | |
try { | |
this.rs.close(); | |
this.st.close(); | |
this.cn.close(); | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.beans.db; | |
public class MyDBAccess11 extends MyDBAccess01 { | |
public static final int GAKUSEKI = 101; | |
public static final int KURASU = 102; | |
public static final int SHUSSEKI = 103; | |
public static final int SHIMEI = 104; | |
public static final int NENREI = 105; | |
public void select() { | |
} | |
public boolean update() { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment