on 05-23-2006 8:45 PM
Hi,
I am trying to call the following class( method add()) but it is giving Nullpointer Exception and URL Malformed Exception. Kindly give the solution. I am giving the program and the comments where i got the Exceptions.
Kidly see the following code. I am getting the exceptions at " doc = saxbuilder.build(fileName); ". Iwant send back the flag after executing this code successfully.
package shoppingcart;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.IOException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.apache.log4j.Logger;
import shoppingcart.dao.DAOUserTable;
import shoppingcart.vo.UserTableVo;
public class UserDB
{
/* public static void main(String[] args) throws JDOMException,IOException
{
} */
Connection con;
DAOUserTable utdao = new DAOUserTable();
UserTableVo pvo = new UserTableVo();
String fileName = "D:
user.xml";
SAXBuilder saxbuilder=new SAXBuilder();
Document doc;
public UserDB() throws IOException,JDOMException
{
<b> doc = saxbuilder.build(fileName);// here I got Nullpointer Exception and URL Malformed Exception
}</b> public boolean add(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try {
con=DriverManager.getConnection("jdbc:odbc:shoppingcart","sa","sa");
} catch (SQLException e) {
System.out.println("Exception ......3 "+e.getMessage());
}
Element root=doc.getRootElement();
Element UId;
UId = root.getChild("UId");
pvo.setUId(UId.getTextTrim());
Element UName;
UName = root.getChild("UName");
pvo.setUName(UName.getTextTrim());
Element Password;
Password = root.getChild("Password");
pvo.setPassword(Password.getTextTrim());
Element Address;
Address = root.getChild("Address");
Element Street;
Street = Address.getChild("Street");
pvo.setStreet(Street.getTextTrim());
Element City;
City = Address.getChild("City");
pvo.setCity(City.getTextTrim());
Element State;
State = Address.getChild("State");
pvo.setState(State.getTextTrim());
Element Country;
Country = Address.getChild("Country");
pvo.setCountry(Country.getTextTrim());
Element Zip;
Zip = Address.getChild("Zip");
pvo.setZip(Zip.getTextTrim());
Element Phone;
Phone = root.getChild("Phone");
pvo.setPhone(Phone.getTextTrim());
Element Mobile;
Mobile = root.getChild("Mobile");
pvo.setMobile(Mobile.getTextTrim());
Element Fax;
Fax = root.getChild("Fax");
pvo.setFax(Fax.getTextTrim());
Element EmailID1;
EmailID1 = root.getChild("EmailID1");
pvo.setEmailID1(EmailID1.getTextTrim());
Element EmailID2;
EmailID2 = root.getChild("EmailID2");
pvo.setEmailID2(EmailID2.getTextTrim());
Element UserType;
UserType = root.getChild("UserType");
pvo.setUserType(UserType.getTextTrim());
boolean flag = false;
try {
flag = utdao.updateUser(con,pvo);
} catch (Exception e)
{
System.out.println("Exception ......4 "+e.getMessage());
}
return flag;
}
}
Thanks & Regards
Rama Krishna
Ram try using this
String fileName = "file:///D:/user.xml";
Regards,
Piyush
ps: please mark for useful answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just checked the API for SAX Builder and it needs File as parameter
Document build(java.io.File file)
so replace
String fileName = "file:///D:/user.xml";
with
File fileName = new File("D:/user.xml");
http://www.jdom.org/docs/apidocs/org/jdom/input/SAXBuilder.html#build(java.io.File)
But I guess, even this should work so check out
String fileName = "file:///D:/user.xml";
Regards,
Piyush
ps: please mark for useful answers.
Rama,
Just use the following form:
final URL url = new URL("file", "", -1, "D:\user.xml");
/*...*/
saxbuilder.build( url.toExternalForm() );
VS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.