java resultset TYPE_SCROLL_INSENSITIVE

https://www.ibm.com/developerworks/jp/java/library/j-5things10.html

java webサービス DTO⇒JSON

●ライブラリ

・Jacksonを使用する

参考URL:http://qiita.com/takehiro224/items/6db2841c0abbf4ffb233

 

DTO

package pack;

public class Info {
public String code;
public String name;
}

 

サーブレット

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

response.setContentType("applicaton/json;charset=UTF-8");
PrintWriter out = response.getWriter();

// ユーザ名
String user = "XXX";
// パスワード
String pass = "XXX";
// サーバ名
String servername = "localhost";
// SID
String sid = "XE";

Connection conn = null;
Statement stmt = null;
ResultSet rset = null;

try {

// JBBCドライバクラスのロード
Class.forName("oracle.jdbc.driver.OracleDriver");

// Connectionの作成
conn = DriverManager.getConnection("jdbc:oracle:thin:@" + servername + ":1521:" + sid, user, pass);

// Statementの作成
stmt = conn.createStatement();

// Resultsetの作成
rset = stmt.executeQuery("select CODE, NAME from FAMILY");

// ResultSetの件数取得
int count = 0;
while (rset.next()) {
count++;
}

// ResultSet → DTO
Info[] info = new Info[count];
int index = 0;
while (rset.next()) {
Info row = new Info();
row.code = rset.getString("CODE");
row.name = rset.getString("NAME");
info[index] = row;
index++;
}

// DTOJSON文字列
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(info);

out.println(json);

} catch (ClassNotFoundException e) {
//throw e;
} catch (SQLException e) {
//throw e;
} catch (Throwable e) {
throw e;
} finally {
try {
/* クローズ処理 */
if (rset != null) {
rset.close();
rset = null;
}

if (stmt != null) {
stmt.close();
stmt = null;
}

if (conn != null) {
conn.close();
conn = null;
}
} catch (Throwable e) {
// nop
}
}
}

 

●Jacksonを使用せず、JSON文字列の作成

// 取得したデータを出力する
// JSON 文字列の書き込み
out.println("\"employees\":[");
while (rset.next()) {
out.println("{\"code\" : \"" + rset.getString("CODE") + "\"," + "\"name\" : \"" + rset.getString("NAME") + "\"}");
}
out.println("]");

HTML Sample002

<!DOCTYPE html>
<html>
<TABLE BORDER="0">
<TR>
<TD>
<table border="1" rules="none">
<col width="150">
<col width="60">
<col width="60">
<col width="60">
<col width="60">
<col width="60">
<tr>
<td>ああああああ</td>
<td>1-2</td>
<td>1-3</td>
<td>1-4</td>
<td>1-5</td>
<td>1-6</td>
</tr>
<tr>
<td>いいい</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
<td>2-5</td>
<td>2-6</td>
</tr>
</table>
</TD>
<TD>
<table border="1" rules="none">
<col width="150">
<col width="60">
<col width="60">
<col width="60">
<col width="60">
<col width="60">
<tr>
<td>ああああああ</td>
<td>1-2</td>
<td>1-3</td>
<td>1-4</td>
<td>1-5</td>
<td>1-6</td>
</tr>
<tr>
<td>いいい</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
<td>2-5</td>
<td>2-6</td>
</tr>
</table>
</TD>
</TR>
</TABLE>
</html>

HTML テーブル横並び

http://siriasu.s10.xrea.com/webtips/tips01.htm

http://www.ynsk.co.jp/smpl/smpl004.htm

HTML Sample001

<!DOCTYPE html>
<html>
<table cellspacing="10">
<col width="150">
<col width="150">
<col width="150">
<col width="150">
<col width="150">
<col width="150">
<tr>
<td>ああああああ</td>
<td>1-2</td>
<td>1-3</td>
<td>1-4</td>
<td>1-5</td>
<td>1-6</td>
</tr>
<tr>
<td>いいい</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
<td>2-5</td>
<td>2-6</td>
</tr>
<tr>
<td>ううう</td>
<td>3-2</td>
<td>3-3</td>
<td>3-4</td>
<td>3-5</td>
<td>3-6</td>
</tr>
<tr>
<td>えええ</td>
<td>4-2</td>
<td>4-3</td>
<td>4-4</td>
<td>4-5</td>
<td>4-6</td>
</tr>
<tr>
<td>おおお</td>
<td>5-2</td>
<td>5-3</td>
<td>5-4</td>
<td>5-5</td>
<td>5-6</td>
</tr>
<tr>
<td>かかかか</td>
<td>6-2</td>
<td>6-3</td>
<td>6-4</td>
<td>6-5</td>
<td>6-6</td>
</tr>
<tr>
<td>AAAAき</td>
<td>7-2</td>
<td>7-3</td>
<td>7-4</td>
<td>7-5</td>
<td>7-6</td>
</tr>
<tr>
<td>AAAAく</td>
<td>8-2</td>
<td>8-3</td>
<td>8-4</td>
<td>8-5</td>
<td>8-6</td>
</tr>
<tr>
<td>けけけ</td>
<td>9-2</td>
<td>9-3</td>
<td>9-4</td>
<td>9-5</td>
<td>9-6</td>
</tr>
<tr>
<td>ここここ/こここ</td>
<td>10-2</td>
<td>10-3</td>
<td>10-4</td>
<td>10-5</td>
<td>10-6</td>
</tr>
<tr>
<td>ささささささささ</td>
<td>11-2</td>
<td>11-3</td>
<td>11-4</td>
<td>11-5</td>
<td>11-6</td>
</tr>
<tr>
<td>ししししし(ししししし)</td>
<td>12-2</td>
<td>12-3</td>
<td>12-4</td>
<td>12-5</td>
<td>12-6</td>
</tr>
<tr>
<td>すすすすすすすす</td>
<td>13-2</td>
<td>13-3</td>
<td>13-4</td>
<td>13-5</td>
<td>13-6</td>
</tr>
<tr>
<td>せせせせせせ</td>
<td>14-2</td>
<td>14-3</td>
<td>14-4</td>
<td>14-5</td>
<td>14-6</td>
</tr>
<tr>
<td>そそそそそそ</td>
<td>15-2</td>
<td>15-3</td>
<td>15-4</td>
<td>15-5</td>
<td>15-6</td>
</tr>
<tr>
<td>たたたた</td>
<td>16-2</td>
<td>16-3</td>
<td>16-4</td>
<td>16-5</td>
<td>16-6</td>
</tr>
</table>
</html>

HTML テーブル

テーブル

http://www.tohoho-web.com/html/table.htm
http://www.kanzaki.com/docs/html/htminfo16.html
http://webworkersclip.com/2875/
http://www.tagindex.com/html_tag/table/col.html
http://www.newcredge.com/IT/www/html/tag/table/table-col.html

テーブルを横に並べる
http://hmaster.net/table12.html

セルを結合する
http://www.tagindex.com/html_tag/table/td_span.html