|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectjp.terasoluna.fw.ex.unit.util.JdbcTemplateUtils
public class JdbcTemplateUtils
JdbcTemplateをラップしたユーティリティクラスです。
| コンストラクタの概要 | |
|---|---|
JdbcTemplateUtils()
|
|
| メソッドの概要 | ||
|---|---|---|
static int[] |
batchUpdate(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String... sqls)
更新系SQLをバッチ実行します。 |
|
static String |
createInsertSql(Class<?> clazz)
指定したクラスの持つフィールド名を全て設定するINSERT文を生成します。 |
|
static String |
createInsertSql(String tableName,
Class<?> clazz)
指定したクラスの持つフィールド名を全て設定するINSERT文を生成します。 |
|
static String |
createInsertSql(String tableName,
String[] fieldNames)
指定したフィールド名を全て設定するINSERT文を生成します。 |
|
static String |
createSelectSql(Class<?> clazz)
指定したクラスの持つフィールド名を全て参照するSELECT文を生成します。 |
|
static String |
createSelectSql(String tableName,
Class<?> clazz)
指定したクラスの持つフィールド名を全て参照するSELECT文を生成します。 |
|
static String |
createSelectSql(String tableName,
String[] fieldNames)
指定したフィールド名を全て参照するSELECT文を生成します。 |
|
static void |
execute(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
任意のSQLを実行します。 |
|
static int |
queryForInt(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
参照系SQLを実行しint型の結果を返却します。 |
|
static int |
queryForInt(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
参照系SQLを実行しint型の結果を返却します。 |
|
static long |
queryForLong(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
参照系SQLを実行しlong型の結果を返却します。 |
|
static long |
queryForLong(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
参照系SQLを実行しlong型の結果を返却します。 |
|
static
|
queryForObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> requiredType)
参照系SQLを実行し指定した型の結果を返却します。 |
|
static
|
queryForObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> requiredType)
参照系SQLを実行し指定した型の結果を返却します。 |
|
static Map<String,?> |
queryForRowMap(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
参照系SQLを実行し1行分の結果を格納した Mapを返却します。 |
|
static Map<String,?> |
queryForRowMap(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
参照系SQLを実行し1行分の結果を格納した Mapを返却します。 |
|
static List<Map<String,?>> |
queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
Class<?> clazz)
指定した型のフィールド情報から参照SQL(全フィールド参照)を生成して実行し、各行の結果を格納した Mapのリストを返却します。 |
|
static List<Map<String,?>> |
queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
参照系SQLを実行し各行の結果を格納した Mapのリストを返却します。 |
|
static List<Map<String,?>> |
queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
参照系SQLを実行し各行の結果を格納した Mapのリストを返却します。 |
|
static
|
queryForRowObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> clazz)
参照系SQLを実行し1行分の結果をT型のオブジェクトにマッピングして返却します。 |
|
static
|
queryForRowObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> clazz)
参照系SQLを実行し1行分の結果をT型のオブジェクトにマッピングして返却します。 |
|
static
|
queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
Class<T> clazz)
指定した型のフィールド情報から参照SQL(全フィールド参照)を生成して実行し、各行の結果をT型のオブジェクトにマッピングしてリストを返却します。 |
|
static
|
queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> clazz)
参照系SQLを実行し各行の結果をT型にマッピングして格納したリストを返却します。 |
|
static
|
queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> clazz)
参照系SQLを実行し各行の結果をT型にマッピングして格納したリストを返却します。 |
|
static
|
queryForSingleColumnList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> elementType)
参照系のSQLを実行し1列分の結果をT型で返却します。 |
|
static
|
queryForSingleColumnList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> elementType)
参照系のSQLを実行し1列分の結果をT型で返却します。 |
|
static String |
queryForString(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
参照系SQLを実行しString型の結果を返却します。 |
|
static String |
queryForString(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
参照系SQLを実行しint型の結果を返却します。 |
|
static int |
update(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
更新系SQLを実行します。 |
|
static int |
update(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
更新系SQLを実行します。 |
|
| クラス java.lang.Object から継承されたメソッド |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| コンストラクタの詳細 |
|---|
public JdbcTemplateUtils()
| メソッドの詳細 |
|---|
public static void execute(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
例 execute(jdbcTemplate, "create table foo(val integer, name varchar2(10))");
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static int update(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static int update(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static int[] batchUpdate(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String... sqls)
throws org.springframework.dao.DataAccessException
jdbcTemplate - JdbcTemplatesqls - バッチ実行するSQLの配列
org.springframework.dao.DataAccessException
public static long queryForLong(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
例 upate(jdbcTemplate, "insert into foo (val) values(100)"); queryForLong(jdbcTemplate, "select val from foo"); // -> 100
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static long queryForLong(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
upate(jdbcTemplate, "insert into foo (val) values(100)");
upate(jdbcTemplate, "insert into foo (val) values(10)");
queryForLong(jdbcTemplate, "select val from foo where val < ?", new Object[]{50}); // -> 10
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static int queryForInt(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
例 upate(jdbcTemplate, "insert into foo (val) values(100)"); queryForInt(jdbcTemplate, "select val from foo"); // -> 100
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static int queryForInt(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
upate(jdbcTemplate, "insert into foo (val) values(100)");
upate(jdbcTemplate, "insert into foo (val) values(10)");
queryForInt(jdbcTemplate, "select val from foo where val < ?", new Object[]{50}); // -> 10
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static String queryForString(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
例 upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample')"); queryForString(jdbcTemplate, "select name from foo"); // -> Sample
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static String queryForString(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForInt(jdbcTemplate, "select name from foo where val < ?", new Object[]{50}); // -> Sample2
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static <T> T queryForObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> requiredType)
throws org.springframework.dao.DataAccessException
T - 返却値の型 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLrequiredType - 返却値の型 返却値の型
org.springframework.dao.DataAccessException
public static <T> T queryForObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> requiredType)
throws org.springframework.dao.DataAccessException
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータrequiredType - 返却値の型
org.springframework.dao.DataAccessException
public static Map<String,?> queryForRowMap(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
Mapを返却します。Mapのキー文字列は大文字・小文字を無視します。
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample')");
queryForRowMap(jdbcTemplate, "select val, name from foo"); // -> {VAL=100, NAME=Sample}
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static Map<String,?> queryForRowMap(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
Mapを返却します。(PreparedStatement使用)Mapのキー文字列は大文字・小文字を無視します。
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowMap(jdbcTemplate, "select val from foo where val < ?", new Object[]{50}); // -> {VAL=10, NAME=Sample2}
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static <T> T queryForRowObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> clazz)
throws org.springframework.dao.DataAccessException
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample')");
queryForRowObject(jdbcTemplate, "select val, name from foo", Foo.class); // -> Foo{val=100, name=Sample}
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLclazz -
org.springframework.dao.DataAccessException
public static <T> T queryForRowObject(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> clazz)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowObject(jdbcTemplate, "select val from foo where val < ?", new Object[]{50}, Foo.class); // -> Foo{val=10, name=Sample2}
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータclazz - 返却値の型
org.springframework.dao.DataAccessException
public static <T> List<T> queryForSingleColumnList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> elementType)
throws org.springframework.dao.DataAccessException
例 upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')"); upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')"); queryForSingleColumnList(jdbcTemplate, "select val from foo", Integer.class); // -> [100, 10]
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLelementType -
org.springframework.dao.DataAccessException
public static <T> List<T> queryForSingleColumnList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> elementType)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForSingleColumnList(jdbcTemplate, "select name from foo where val > ?",
new Object[] { 0 }, String.class);
// -> [Sample1, Sample2]
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータelementType -
org.springframework.dao.DataAccessException
public static List<Map<String,?>> queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql)
throws org.springframework.dao.DataAccessException
Mapのリストを返却します。
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowMapList(jdbcTemplate, "select val, name from foo");
// -> [{VAL=100, NAME=Sample1}, {VAL=10, NAME=Sample2}]
jdbcTemplate - JdbcTemplatesql - 実行するSQL
org.springframework.dao.DataAccessException
public static List<Map<String,?>> queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args)
throws org.springframework.dao.DataAccessException
Mapのリストを返却します。(PreparedStatement使用)
例
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowMapList(jdbcTemplate, "select val, name from foo where val > ?",
new Object[] { 0 });
// -> [{VAL=100, NAME=Sample1}, {VAL=10, NAME=Sample2}]
jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータ
org.springframework.dao.DataAccessException
public static List<Map<String,?>> queryForRowMapList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
Class<?> clazz)
throws org.springframework.dao.DataAccessException
Mapのリストを返却します。 createSelectSql(Class)より生成します。
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowMapList(jdbcTemplate, Foo.class);
// -> [{VAL=100, NAME=Sample1}, {VAL=10, NAME=Sample2}]
jdbcTemplate - JdbcTemplateclazz - 返却値の型
org.springframework.dao.DataAccessException
public static <T> List<T> queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Class<T> clazz)
throws org.springframework.dao.DataAccessException
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowOnjectList(jdbcTemplate, "select val, name from foo", Foo.class);
// -> [Foo{val=100, name=Sample1}, Foo{val=10, name=Sample2}]
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLclazz - 返却値の型
org.springframework.dao.DataAccessException
public static <T> List<T> queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String sql,
Object[] args,
Class<T> clazz)
throws org.springframework.dao.DataAccessException
PreparedStatement使用)
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowOnjectList(jdbcTemplate, "select val, name from foo where val > ?", new Object[] {0}, Foo.class);
// -> [Foo{val=100, name=Sample1}, Foo{val=10, name=Sample2}]
T - 返却値の型jdbcTemplate - JdbcTemplatesql - 実行するSQLargs - プリペアドステートメントのパラメータclazz - 返却値の型
org.springframework.dao.DataAccessException
public static <T> List<T> queryForRowObjectList(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
Class<T> clazz)
throws org.springframework.dao.DataAccessException
createSelectSql(Class)より生成します。
Springのバージョンが2.5以上である必要があります。
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
upate(jdbcTemplate, "insert into foo (val, name) values(100, 'Sample1')");
upate(jdbcTemplate, "insert into foo (val, name) values(10, 'Sample2')");
queryForRowOnjectList(jdbcTemplate, Foo.class);
// -> [Foo{val=100, name=Sample1}, Foo{val=10, name=Sample2}]
T - 返却値の型jdbcTemplate - JdbcTemplateclazz - 返却値の型
org.springframework.dao.DataAccessException
public static String createSelectSql(String tableName,
String[] fieldNames)
例
createSelectSql("foo", new String[] {"val", "name"}); // SELECT val,name FROM foo
tableName - テーブル名fieldNames - フィールド名
public static String createSelectSql(String tableName,
Class<?> clazz)
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
createSelectSql("foo", Foo.clas); // -> SELECT val,name FROM foo
tableName - テーブル名clazz - クラス名
public static String createSelectSql(Class<?> clazz)
例
public class Foo {
private int val;
private String name;
// setter/getter略
}
createSelectSql(Foo.clas); // -> SELECT val,name FROM Foo
clazz - クラス名
public static String createInsertSql(String tableName,
String[] fieldNames)
例
createInsertSql("foo", new String[] {"val", "name"}); // INSERT INTO foo (val,name) VALUES(?,?)
tableName - テーブル名fieldNames - フィールド名
public static String createInsertSql(String tableName,
Class<?> clazz)
例
createInsertSql("foo", Foo.class); // INSERT INTO foo (val,name) VALUES(?,?)
tableName - テーブル名clazz - クラス名
public static String createInsertSql(Class<?> clazz)
例 createInsertSql(Foo.class); // INSERT INTO Foo (val,name) VALUES(?,?)
clazz - クラス名
|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||