struts徭協吶炎禰?糞?廓曝和性僉夲崇
扮寂:2011-03-20
1 package com.pmjava.web.taglib;
2 import com.pmjava.jdbc.util.ConnectionFactory;
3 import com.pmjava.jdbc.util.DBclose;
4 import java.io.PrintStream;
5 import java.sql.*;
6 import javax.servlet.jsp.*;
7 import javax.servlet.jsp.tagext.TagSupport;
8 public class DbSelectByDbWhere extends TagSupport
9 {
10 private static final long serialVersionUID = 1L;
11 private String table_name;
12 private String id_col_name;
13 private String select_id;
14 private String name;
15 private String name_col_name;
16 private String condition;
17 private String pleaseselect;
18 private String sql_where;
19 private String id;
20 PreparedStatement ps;
21 ResultSet rs;
22 Connection con;
23 public DbSelectByDbWhere()
24 {
25 ps = null;
26 rs = null;
27 con = null;
28 try
29 {
30 jbInit();
31 }
32 catch (Exception ex)
33 {
34 ex.printStackTrace();
35 }
36 }
37 public int doStartTag()
38 throws JspException
39 {
40 if (sql_where == null || "null".equals(sql_where))
41 sql_where = "";
42 if (condition == null || "null".equals(condition))
43 condition = "";
44 try
45 {
46 con = ConnectionFactory.getConnection();
47 pageContext.getOut().write("");
48 if ("1".equals(pleaseselect))
49 pageContext.getOut().write("僉夲廓曝");
50 String Selected = null;
51 String Sql = "select * from " + table_name + " where 1=1 ";
52 if (!"".equals(sql_where) || sql_where != null)
53 Sql = Sql + " and city_id=" + sql_where + " ";
54 ps = con.prepareStatement(Sql);
55 for (rs = ps.executeQuery(); rs.next(); pageContext.getOut().write("" + rs.getString(name_col_name) + ""))
56 if (rs.getString(name_col_name).equals(select_id))
57 Selected = "selected";
58 else
59 Selected = "";
60 pageContext.getOut().write("");
61 }
62 catch (Exception e)
63 {
64 e.printStackTrace();
65 }
66 finally
67 {
68 DBclose.close(rs, ps, con);
69 }
70 return 0;
71 }
72 public void setTable_name(String table_name)
73 {
74 this.table_name = table_name;
75 }
76 public void setId_col_name(String id_col_name)
77 {
78 this.id_col_name = id_col_name;
79 }
80 public void setSelect_id(String select_id)
81 {
82 this.select_id = select_id;
83 }
84 public void setName(String name)
85 {
86 this.name = name;
87 }
88 public void setName_col_name(String name_col_name)
|