第一步:
第二步:
第三步:
package dddd;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
public class A {
public static void main(String[] args) {
ApplicationContext ac=new ClassPathXmlApplicationContext("classpath:kk.xml");
final JdbcTemplate jt=(JdbcTemplate)ac.getBean("jdbcTemplate");
// jt.query("select * from test", new RowCallbackHandler(){
// public void processRow(ResultSet rs) throws SQLException {
// String content=rs.getString(2);
// String[] contents=content.split("\W"); //本来一个表,分词:原来的table+分词table--->原来的id(在分词表中不是主键)
// for(String single:contents){
// String sqlinsert="insert test1(id,singleword) values(?,?)";
// Object[] args={rs.getInt(1),single};
// jt.update(sqlinsert,args);
// }
// }
// });
String sin="kk";
jt.query("select * from test where id in (select id from test1 where singleword='"+sin+"')", new RowCallbackHandler(){ //分词查询结果
public void processRow(ResultSet rs) throws SQLException {
System.out.println(rs.getInt("id")+".."+rs.getString(2));
}
});
}
}