M
mills
I have been working on the following bean for several days and not
getting very far. I think I am missing something but my java knowledge
is limited.
Here are the relivent pieces of code...
package com.mysoftware.poorderItem;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class poorderItemBean implements
HttpSessionBindingListener,Serializable {
private boolean hasError;
private boolean needsConfirm;
private String rawItem;
private String evalItem;
private String Desc1;
private String Desc2;
private String driver = "net.sourceforge.jtds.jdbc.Driver";
private String DBIPAddr = "";
private String url = "jdbc:jtds:sqlserver:";
private String user;
private String pass;
private Connection con;
private HttpSession session;
private ServletContext sc;
public poorderItemBean() {
initValues();
}
private void initValues() {
hasError = true;
needsConfirm = false;
rawItem = null;
evalItem = null;
Desc1 = null;
Desc2 = null;
lineid = -1;
}
private void initDBstuff() {
DBIPAddr = sc.getInitParameter("DatabaseIPAddr");
user = sc.getInitParameter("DatabaseUser");
pass = sc.getInitParameter("DatabasePassword");
url = url + DBIPAddr.trim();
}
public void valueBound(HttpSessionBindingEvent event) {
session = event.getSession();
sc = session.getServletContext();
initDBstuff();
}
public void valueUnbound(HttpSessionBindingEvent event) {
session = null;
sc = null;
}
public String getRawPartNumber() {
return rawItem;
}
public String getPartNumber() {
return evalItem;
}
public void setPartNumber (String pn) {
String tempPartNumber = null;
if (!pn.trim().equals(this.evalItem.trim())) {
// Lookup new description and price
try {
Class.forName(driver);
con = DriverManager.getConnection(url,user,pass);
CallableStatement cs = con.prepareCall("{call EvalCustPOLine
?,?}");
CallableStatement cs1 = con.prepareCall("{call HuntforCatpart
?}");
PreparedStatement ps1 = con.prepareStatement("Select in_Catpart
from dbo.Inventory where in_Catpart = ? and in_Delete=0");
PreparedStatement ps2 = con.prepareStatement("Select in_Catpart,
in_Desc, in_Desc2, in_Nonstock from dbo.Inventory where in_Catpart = ?
and in_Delete=0");
ResultSet rsInvent1;
ResultSet rsInvent2;
ResultSet rsEval;
ResultSet rsHunt;
ps1.setString(1,pn.trim());
rsInvent1 = ps1.executeQuery();
while (rsInvent1.next()) {
tempPartNumber = rsInvent1.getString("in_Catpart").trim();
}
rsInvent1.close();
ps1.close();
if (tempPartNumber==null) {
//Hunt for part number
this.hasError = true;
cs1.setString(1,pn.trim());
rsHunt = cs1.executeQuery();
while(rsHunt.next()) {
tempPartNumber = rsHunt.getString("Suggestion").trim();
if (rsHunt.getInt("Matches")==1) {
this.needsConfirm = true;
this.hasError = false;
} else {
this.needsConfirm = false;
this.hasError = true;
}
}
rsHunt.close();
cs1.close();
}
//Load Description and price
this.evalItem = null;
this.Desc1 = null;
this.Desc2 = null;
this.IsSpecialorder = false;
if (tempPartNumber!=null) {
ps2.setString(1,tempPartNumber);
rsInvent2 = ps2.executeQuery();
while (rsInvent2.next()) {
this.evalItem = rsInvent2.getString("in_Catpart").trim();
this.Desc1 = rsInvent2.getString("in_Desc").trim();
this.Desc2 = rsInvent2.getString("in_Desc2").trim();
this.IsSpecialorder = rsInvent2.getBoolean("in_NonStock");
}
rsInvent2.close();
ps2.close();
}
} catch (Exception e) {
sc.log("Exception caught (poorderItemBean) : "+e.getMessage());
}
}
}
When I call setPartNumber() I get an exception. It looks like it hasn't
assigned a session or servletcontext yet. I am trying to get the
database connection information from the web.xml file.
Any help/suggestions?
Thanks,
Tim
P.S. Sorry if this appears as a cross post. I posted in
comp.lang.java.beans a few days ago and there doesn't seem to be any
activity there.
getting very far. I think I am missing something but my java knowledge
is limited.
Here are the relivent pieces of code...
package com.mysoftware.poorderItem;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class poorderItemBean implements
HttpSessionBindingListener,Serializable {
private boolean hasError;
private boolean needsConfirm;
private String rawItem;
private String evalItem;
private String Desc1;
private String Desc2;
private String driver = "net.sourceforge.jtds.jdbc.Driver";
private String DBIPAddr = "";
private String url = "jdbc:jtds:sqlserver:";
private String user;
private String pass;
private Connection con;
private HttpSession session;
private ServletContext sc;
public poorderItemBean() {
initValues();
}
private void initValues() {
hasError = true;
needsConfirm = false;
rawItem = null;
evalItem = null;
Desc1 = null;
Desc2 = null;
lineid = -1;
}
private void initDBstuff() {
DBIPAddr = sc.getInitParameter("DatabaseIPAddr");
user = sc.getInitParameter("DatabaseUser");
pass = sc.getInitParameter("DatabasePassword");
url = url + DBIPAddr.trim();
}
public void valueBound(HttpSessionBindingEvent event) {
session = event.getSession();
sc = session.getServletContext();
initDBstuff();
}
public void valueUnbound(HttpSessionBindingEvent event) {
session = null;
sc = null;
}
public String getRawPartNumber() {
return rawItem;
}
public String getPartNumber() {
return evalItem;
}
public void setPartNumber (String pn) {
String tempPartNumber = null;
if (!pn.trim().equals(this.evalItem.trim())) {
// Lookup new description and price
try {
Class.forName(driver);
con = DriverManager.getConnection(url,user,pass);
CallableStatement cs = con.prepareCall("{call EvalCustPOLine
?,?}");
CallableStatement cs1 = con.prepareCall("{call HuntforCatpart
?}");
PreparedStatement ps1 = con.prepareStatement("Select in_Catpart
from dbo.Inventory where in_Catpart = ? and in_Delete=0");
PreparedStatement ps2 = con.prepareStatement("Select in_Catpart,
in_Desc, in_Desc2, in_Nonstock from dbo.Inventory where in_Catpart = ?
and in_Delete=0");
ResultSet rsInvent1;
ResultSet rsInvent2;
ResultSet rsEval;
ResultSet rsHunt;
ps1.setString(1,pn.trim());
rsInvent1 = ps1.executeQuery();
while (rsInvent1.next()) {
tempPartNumber = rsInvent1.getString("in_Catpart").trim();
}
rsInvent1.close();
ps1.close();
if (tempPartNumber==null) {
//Hunt for part number
this.hasError = true;
cs1.setString(1,pn.trim());
rsHunt = cs1.executeQuery();
while(rsHunt.next()) {
tempPartNumber = rsHunt.getString("Suggestion").trim();
if (rsHunt.getInt("Matches")==1) {
this.needsConfirm = true;
this.hasError = false;
} else {
this.needsConfirm = false;
this.hasError = true;
}
}
rsHunt.close();
cs1.close();
}
//Load Description and price
this.evalItem = null;
this.Desc1 = null;
this.Desc2 = null;
this.IsSpecialorder = false;
if (tempPartNumber!=null) {
ps2.setString(1,tempPartNumber);
rsInvent2 = ps2.executeQuery();
while (rsInvent2.next()) {
this.evalItem = rsInvent2.getString("in_Catpart").trim();
this.Desc1 = rsInvent2.getString("in_Desc").trim();
this.Desc2 = rsInvent2.getString("in_Desc2").trim();
this.IsSpecialorder = rsInvent2.getBoolean("in_NonStock");
}
rsInvent2.close();
ps2.close();
}
} catch (Exception e) {
sc.log("Exception caught (poorderItemBean) : "+e.getMessage());
}
}
}
When I call setPartNumber() I get an exception. It looks like it hasn't
assigned a session or servletcontext yet. I am trying to get the
database connection information from the web.xml file.
Any help/suggestions?
Thanks,
Tim
P.S. Sorry if this appears as a cross post. I posted in
comp.lang.java.beans a few days ago and there doesn't seem to be any
activity there.