import com.b029.action.Untitled2;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
public class tool {
public String getSQL(String[] temp) {
StringBuffer str_temp = new StringBuffer();
str_temp.append("---------------------SQL语句开始-------------------/n");
str_temp.append("insert into temp values(");
for (int i = 1; i < temp.length; i++) {
str_temp.append("'/"+");
str_temp.append("Common.zh(from1.get" + temp[i] + "())");
str_temp.append("+/n/"',");
}
str_temp.append(")/n");
str_temp.append("update temp set ");
for (int i = 1; i < temp.length; i++) {
str_temp.append(""+temp[i]+"='/"+from1.get"+temp[i]+"()+/"',");
}
str_temp.append(" where temp.id=/n");
str_temp.append("select ");
for (int i = 1; i < temp.length; i++) {
if(i%4==0){
str_temp.append("" + temp[i] + ",");
str_temp.append("/"+/n");
str_temp.append("/"");
}else{
str_temp.append("" + temp[i] + ",");
}
}
str_temp.append("from");
return str_temp.toString();
}
public String jspshow(String[] temp){
StringBuffer str_temp = new StringBuffer();
str_temp.append("---------------------jsp页面开始-------------------/n");
str_temp.append("if (request.getAttribute(/"listseclevel/")!=null){/n");
str_temp.append(
"ArrayList list1 = (ArrayList) request.getAttribute(/"listseclevel/")/n");
str_temp.append("Iterator itt = list1.iterator();/n");
str_temp.append("while (itt.hasNext()) {/n");
str_temp.append("fstlevelForm from = (fstlevelForm) itt.next();/n");
for (int i = 1; i < temp.length; i++) {
str_temp.append("String "+temp[i]+" = from.get"+temp[i]+"();/n");
}
str_temp.append("}/n");
return str_temp.toString();
}
public String fromset(String[] temp) {
StringBuffer str_temp = new StringBuffer();
str_temp.append("---------------------from给值开始-------------------/n");
str_temp.append("ArrayList list = new ArrayList();/nDB2 db = new DB2();/n");
str_temp.append(
"String sql = /"select id,eatery_id,pic,pic_content from uploadpic/";/n");
str_temp.append(
"ResultSet rs = db.getrs(sql);/ntry {/n while (rs.next()) {/n");
for (int i = 1; i < temp.length; i++) {
str_temp.append("from.set"+temp[i]+"(rs.getString(/""+temp[i]+"/"));/n");
}
str_temp.append("list.add(from);/n");
str_temp.append("}/n} catch (SQLException ex) {}/n");
return str_temp.toString();
}
public String getJavaBean(String[] temp) {
StringBuffer str_temp = new StringBuffer();
str_temp.append("---------------------得到javabean开始-------------------/n");
for (int i = 1; i < temp.length; i++) {
str_temp.append("String " + temp[i] + "=/"/";/n");
}
for (int i = 1; i < temp.length; i++) {
str_temp.append("public String get" + temp[i] + "(){/n");
str_temp.append("return this." + temp[i] + ";/n");
str_temp.append("}/n");
str_temp.append("public void set" + temp[i] + "(String " + temp[i] +
"){/n");
str_temp.append("this." + temp[i] + "=" + temp[i] + ";/n");
str_temp.append("}/n");
}
return str_temp.toString();
}
public String[] getfiled(String table){
daoSQL daosql = new daoSQL();
ResultSet rs=daosql.returnRs("select * from "+table+"");
try {
ResultSetMetaData rsmd = rs.getMetaData();
int i = rsmd.getColumnCount();
String[] temp=new String[i+1];
for (int temp_i = 1; temp_i <= i; temp_i++) {
temp[temp_i]=rsmd.getColumnName(temp_i);
}
return temp;
} catch (SQLException ex) {
System.out.print(ex);
}
return null;
}
public static void main(String[] args) {
tool ss = new tool();
String[] temp =ss.getfiled("uploadpic");
System.out.print(ss.getJavaBean(temp));
System.out.print(ss.fromset(temp));
System.out.print(ss.jspshow(temp));
System.out.print(ss.getSQL(temp));
}
}
使用请注意:
//daoSQL需要改成自己的
7529

被折叠的 条评论
为什么被折叠?



