|
 |
pro_jsp thread: JSP to Bean Static??
Message #1 by at459@h... on Tue, 9 Jan 2001 16:00:16 -0000
|
|
I could be wrong, but try without initializing sub to
null.
--- at459@h... wrote:
>
> I'm using a JSP to Bean setup to access a database.
>
> The JSP set's the property for one variable in the
> Bean:
> <jsp:setProperty name="beanie" property="sub"
> value="insane" />
>
> The Bean then uses "varx" in a SQL SELECT to pulll
> the info from the
> database.
>
> Simple enough. What is driving me nuts is that,
> unless I declare "sub" as
> a class variable (static) in the Bean, I get no
> results pulled from the
> database.
>
> In other words if I declare private String sub;
> instead of private static
> String sub; I get nothing, zip, nada.
>
> Having to use a staic variable is causing other
> problems since the Bean is
> accessed by a few JSPs and I can't see any reason
> why the variable should
> have to be static.
>
> Does anyone have any clue as to what could be
> happening?
>
>
> *This* is the version of the Bean that works, but if
> I remove static from
> the declaration of sub and subz it simply doesn't
> return any results
>
> package brean;
> import java.beans.*;
> import java.sql.*;
> import java.util.*;
>
> public class NulisttopicBean {
> private static String idz[];
> private static String date[];
> private static String body[];
> private static String title[];
> private static String byline[];
> private static String source[];
> private static String sub = null;
> private static String subz = null;
>
> public static String[] getIdz() {return idz; }
> public static String[] getDate() {return date;}
> public static String[] getTitle() {return title;}
> public static String[] getSource() {return source;}
> public static String[] getBody() {return body;}
> public static String[] getByline() {return byline;}
>
> public String getDate(int id) {
> for(int i=0;i<title.length;i++)
> return date[i];
> return null;
> }
>
> public String getBody(int id) {
> for(int i=0;i<title.length;i++)
> return title[i];
> return null;
> }
>
> public String getSub() {
> return sub;
> }
>
> public void setSub (String sub){
> this.sub = sub;
> }
>
> public void setSubz (String subz){
> this.subz = subz;
> }
> public String getSubz() {
> return subz;
> }
>
> public NulisttopicBean() {
> try {
>
> Class.forName("org.gjt.mm.mysql.Driver");
>
> String url = "ttt";
> Connection con = DriverManager.getConnection(url,
> "ttt", "pass");
>
> Statement st = con.createStatement();
> ResultSet rs = st.executeQuery("SELECT * FROM
> article WHERE subject = '" +
> sub + "' OR subject2 = '" + sub + "' ORDER BY date
> DESC");
>
> Vector idzV = new Vector();
> Vector dateV = new Vector();
> Vector titleV = new Vector();
> Vector sourceV = new Vector();
> Vector bylineV = new Vector();
>
> while(rs.next()) {
> idzV.addElement(rs.getString("id"));
> dateV.addElement(rs.getString("date"));
> bylineV.addElement(rs.getString("byline"));
> titleV.addElement(rs.getString("title"));
> sourceV.addElement(rs.getString("source"));
>
> }
> rs.close();
> st.close();
>
> idz = new String[idzV.size()];
> date = new String[dateV.size()];
> title = new String[titleV.size()];
> byline = new String[bylineV.size()];
> source = new String[sourceV.size()];
>
> for(int i=0;i<dateV.size();i++) {
> idz[i] = (String) idzV.elementAt(i);
> date[i] = (String) dateV.elementAt(i);
> title[i] = (String) titleV.elementAt(i);
> byline[i] = (String) bylineV.elementAt(i);
> source[i] = (String) sourceV.elementAt(i);
>
> }
>
> }
>
> catch (Exception e) {
> e.printStackTrace(System.err);
> }
>
> }
---
NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS? Is FREE okay?
Visit EarthWeb for the latest in IT Management, Software Development,
Web Development, Networking & Communications, and Hardware & Systems.
Click on http://www.earthweb.com for FREE articles, tutorials,
and discussions from the experts.
---
You are currently subscribed to pro_jsp as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-pro_jsp-$subst('Recip.MemberIDChar')@p2p.wrox.com
|
|
 |