私の文字列であるsetValues()
メソッドから文字列を取得したい。これをのメソッドに使用したい。誰かがこれを達成するのを手伝ってくれますか? 以下は私のクラスです:ItemPreparedStatementSetter
SQL
String
setSql()
ItemWriter
PreparedStatementSetter
public class PreparedStatementSetter implements
ItemPreparedStatementSetter<Object>{
public static final int INT = 4;
public static final int STRING = 12;
public void setValues(Object item, PreparedStatement ps)
throws SQLException{
@SuppressWarnings({ "rawtypes", "unchecked" })
Map<String, Object> map = (LinkedHashMap) item;
int i = 0;
String columnType;
String sql="";
String final_sql;
try {
sql=generateSql();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int len=map.size();
for(int k=0 ; k<len ; k++)
{
sql=sql+","+"?";
}
sql=sql+")";
// i want to use this final_sql string in setsql() method of itemwriter
final_sql=sql.replaceFirst("," , " ");
for (Map.Entry<String, Object> entry : map.entrySet()) {
i++;
columnType = entry.getKey().substring(0,
(entry.getKey().indexOf("_")));
switch (Integer.parseInt(columnType)) {
case INT: {
ps.setInt(i, (Integer) (entry.getValue()));
break;
}
case STRING: {
ps.setString(i, (String) (entry.getValue()));
break;
}
}
}
}
private String generateSql()
throws ParserConfigurationException, SAXException, IOException
{
String sql="";
Insert insert;
String table="";
try
{
File is = new File("C:/Users/AMDecalog.Trainees/workspace/SpringJobExecuter/config/input1.xml");
JAXBContext context = JAXBContext.newInstance(Insert.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
insert = (Insert) unmarshaller.unmarshal(is);
Insert in = insert;
List<String> into = in.getInto().getTablename();
for(String s : into)
{
table = table+s;
System.out.println(table);
}
sql = "insert into" + " " + table + " " + "values(";
System.out.println(sql);
}
catch (JAXBException e)
{
e.printStackTrace();
}
return sql;
}