这是报的错误Exception in thread "main" java.lang.NullPointerException
at com.hou.test.Test.main(Test.java:38)
Hibernate: select orderform0_.Id as Id2_, orderform0_.usersId as usersId2_, orderform0_.shopId as shopId2_, orderform0_.dineTime as dineTime2_, orderform0_.initalAmount as initalAm5_2_, orderform0_.finalAmount as finalAmo6_2_, orderform0_.meno as meno2_, orderform0_.cost as cost2_, orderform0_.state as state2_, orderform0_.orderType as orderType2_, orderform0_.deskAmount as deskAmount2_, orderform0_.name as name2_, orderform0_.gender as gender2_, orderform0_.tel as tel2_, orderform0_.succCount as succCount2_ from order orderform0_ where orderform0_.initalAmount=2 order by orderform0_.dineTime desc
could not execute query我用的是SQLSERVER数据库.
1,实体类package com.hou.actionForm;import org.apache.struts.action.ActionForm;
public class OrderForm extends ActionForm{
public OrderForm() {}
private static final long serialVersionUID = 1L;
private String id="";
private int usersId=-1;
private String shopId="";
private String dineTime="";
private int initalAmount=-1;
private int finalAmount=-1;
private String meno="";
private Float cost;
private String state;
private String orderType;
private int deskAmount=-1;
private String name;
private String gender;
private String tel;
private Integer succCount;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUsersId() {
return usersId;
}
public void setUsersId(int usersId) {
this.usersId = usersId;
}
public String getDineTime() {
return dineTime;
}
public void setDineTime(String dineTime) {
this.dineTime = dineTime;
}
public int getInitalAmount() {
return initalAmount;
}
public void setInitalAmount(int initalAmount) {
this.initalAmount = initalAmount;
}
public int getFinalAmount() {
return finalAmount;
}
public void setFinalAmount(int finalAmount) {
this.finalAmount = finalAmount;
}
public String getMeno() {
return meno;
}
public void setMeno(String meno) {
this.meno = meno;
}
public Float getCost() {
return cost;
}
public void setCost(Float cost) {
this.cost = cost;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public int getDeskAmount() {
return deskAmount;
}
public void setDeskAmount(int deskAmount) {
this.deskAmount = deskAmount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getSuccCount() {
return succCount;
}
public void setSuccCount(int succCount) {
this.succCount = succCount;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hou.actionForm.UsersForm" table="Users" >
<id name="id" type="int">
<column name="id" />
<generator class="increment" />
</id>
<property name="jobNumber" type="string"></property>
<property name="password" type="string"></property>
<property name="priority" type="int"></property>
</class>
</hibernate-mapping><?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class"><!--指定连接数据库用的驱动-->
net.sourceforge.jtds.jdbc.Driver
</property>
<property name="connection.url"><!--指定连接数据库的路径-->
jdbc:jtds:sqlserver://localhost:1433/WebDB
</property>
<property name="connection.username">sa</property><!--指定连接数据库的用户名-->
<property name="connection.password">sa</property><!--指定连接数据库的密码-->
<property name="show_sql">true</property><!--当show_sql属性为true时表示在程序运行时在控制台输出SQL语句,默认为false,建议在调试程序时设为true,发布程序之前再改为false,因为输出SQL语句会影响程序的运行速度-->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="com/hou/actionForm/UsersForm.hbm.xml"/><!--指定持久化类映射文件-->
<mapping resource="com/hou/actionForm/FeedbackForm.hbm.xml"/>
<mapping resource="com/hou/actionForm/OrderForm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我写的业务方法
public void deleteOrder(String id){
Session session = sessionFactory.openSession();
try {
tx = session.beginTransaction();
OrderForm form=(OrderForm)session.load(OrderForm.class,id);
session.delete(form);
tx.commit();
} catch (Exception e) {
System.out.println("删除数据出错:" + e);
} finally {
session.close();
}
}
下面是测试MAIN方法 OrderDao order=new OrderDao();
List l=order.selectInitOrder();
//order.deleteOrder("123");
System.out.println(l.isEmpty());完了就报上面的那个错误了.大家帮忙给解决下,在线的等待.
at com.hou.test.Test.main(Test.java:38)
Hibernate: select orderform0_.Id as Id2_, orderform0_.usersId as usersId2_, orderform0_.shopId as shopId2_, orderform0_.dineTime as dineTime2_, orderform0_.initalAmount as initalAm5_2_, orderform0_.finalAmount as finalAmo6_2_, orderform0_.meno as meno2_, orderform0_.cost as cost2_, orderform0_.state as state2_, orderform0_.orderType as orderType2_, orderform0_.deskAmount as deskAmount2_, orderform0_.name as name2_, orderform0_.gender as gender2_, orderform0_.tel as tel2_, orderform0_.succCount as succCount2_ from order orderform0_ where orderform0_.initalAmount=2 order by orderform0_.dineTime desc
could not execute query我用的是SQLSERVER数据库.
1,实体类package com.hou.actionForm;import org.apache.struts.action.ActionForm;
public class OrderForm extends ActionForm{
public OrderForm() {}
private static final long serialVersionUID = 1L;
private String id="";
private int usersId=-1;
private String shopId="";
private String dineTime="";
private int initalAmount=-1;
private int finalAmount=-1;
private String meno="";
private Float cost;
private String state;
private String orderType;
private int deskAmount=-1;
private String name;
private String gender;
private String tel;
private Integer succCount;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUsersId() {
return usersId;
}
public void setUsersId(int usersId) {
this.usersId = usersId;
}
public String getDineTime() {
return dineTime;
}
public void setDineTime(String dineTime) {
this.dineTime = dineTime;
}
public int getInitalAmount() {
return initalAmount;
}
public void setInitalAmount(int initalAmount) {
this.initalAmount = initalAmount;
}
public int getFinalAmount() {
return finalAmount;
}
public void setFinalAmount(int finalAmount) {
this.finalAmount = finalAmount;
}
public String getMeno() {
return meno;
}
public void setMeno(String meno) {
this.meno = meno;
}
public Float getCost() {
return cost;
}
public void setCost(Float cost) {
this.cost = cost;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public int getDeskAmount() {
return deskAmount;
}
public void setDeskAmount(int deskAmount) {
this.deskAmount = deskAmount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getSuccCount() {
return succCount;
}
public void setSuccCount(int succCount) {
this.succCount = succCount;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hou.actionForm.UsersForm" table="Users" >
<id name="id" type="int">
<column name="id" />
<generator class="increment" />
</id>
<property name="jobNumber" type="string"></property>
<property name="password" type="string"></property>
<property name="priority" type="int"></property>
</class>
</hibernate-mapping><?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class"><!--指定连接数据库用的驱动-->
net.sourceforge.jtds.jdbc.Driver
</property>
<property name="connection.url"><!--指定连接数据库的路径-->
jdbc:jtds:sqlserver://localhost:1433/WebDB
</property>
<property name="connection.username">sa</property><!--指定连接数据库的用户名-->
<property name="connection.password">sa</property><!--指定连接数据库的密码-->
<property name="show_sql">true</property><!--当show_sql属性为true时表示在程序运行时在控制台输出SQL语句,默认为false,建议在调试程序时设为true,发布程序之前再改为false,因为输出SQL语句会影响程序的运行速度-->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="com/hou/actionForm/UsersForm.hbm.xml"/><!--指定持久化类映射文件-->
<mapping resource="com/hou/actionForm/FeedbackForm.hbm.xml"/>
<mapping resource="com/hou/actionForm/OrderForm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我写的业务方法
public void deleteOrder(String id){
Session session = sessionFactory.openSession();
try {
tx = session.beginTransaction();
OrderForm form=(OrderForm)session.load(OrderForm.class,id);
session.delete(form);
tx.commit();
} catch (Exception e) {
System.out.println("删除数据出错:" + e);
} finally {
session.close();
}
}
下面是测试MAIN方法 OrderDao order=new OrderDao();
List l=order.selectInitOrder();
//order.deleteOrder("123");
System.out.println(l.isEmpty());完了就报上面的那个错误了.大家帮忙给解决下,在线的等待.
解决方案 »
- mina框架服务器与客户端不能互发字节数组
- 学习JAVA一年多的困惑
- struts2 标签 textfield
- 奇怪的自动打开新页面
- 求助:哪位大哥哥有 commons-fileupload 组件的中文文档啊,小弟实在是看不懂英文文档,- -!
- 一个javascript验证struts表单的问题
- 关于在标签中调用spring的bean的问题
- java对时间进行循环放到List中
- 问了三次了,还是没有解决,写了context.getRequestDispatcher后前面的javascript就不再执行了
- 如何配置web.xml文件??????
- 一个hiberante的问题
- Axis2 1.3 POJO guide里的例子通过Axis2的Service Achiever插件发布,调用服务问题!
package com.hou.actionForm;import org.apache.struts.action.ActionForm;
public class OrderForm extends ActionForm{
public OrderForm() {}
private String id="";
private int usersId=-1;
private String shopId="";
private String dineTime="";
private int initalAmount=-1;
private int finalAmount=-1;
private String meno="";
private Float cost;
private String state;
private String orderType;
private int deskAmount=-1;
private String name;
private String gender;
private String tel;
private Integer succCount;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUsersId() {
return usersId;
}
public void setUsersId(int usersId) {
this.usersId = usersId;
}
public String getDineTime() {
return dineTime;
}
public void setDineTime(String dineTime) {
this.dineTime = dineTime;
}
public int getInitalAmount() {
return initalAmount;
}
public void setInitalAmount(int initalAmount) {
this.initalAmount = initalAmount;
}
public int getFinalAmount() {
return finalAmount;
}
public void setFinalAmount(int finalAmount) {
this.finalAmount = finalAmount;
}
public String getMeno() {
return meno;
}
public void setMeno(String meno) {
this.meno = meno;
}
public Float getCost() {
return cost;
}
public void setCost(Float cost) {
this.cost = cost;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public int getDeskAmount() {
return deskAmount;
}
public void setDeskAmount(int deskAmount) {
this.deskAmount = deskAmount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getSuccCount() {
return succCount;
}
public void setSuccCount(int succCount) {
this.succCount = succCount;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hou.actionForm.OrderForm" table="order">
<id name="id" type="int">
<column name="Id" length="50" />
<generator class="assigned" />
</id>
<property name="usersId" type="int">
</property>
<property name="shopId" type="string">
</property>
<property name="dineTime" type="string">
</property>
<property name="initalAmount" type="int">
</property>
<property name="finalAmount" type="int">
</property>
<property name="meno" type="string">
</property>
<property name="cost" type="float">
</property>
<property name="state" type="string">
</property>
<property name="orderType" type="string">
</property>
<property name="deskAmount" type="int">
</property>
<property name="name" type="string">
</property>
<property name="gender" type="string">
</property>
<property name="tel" type="string">
</property>
<property name="succCount" type="int">
</property>
</class>
</hibernate-mapping>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class"><!--指定连接数据库用的驱动-->
net.sourceforge.jtds.jdbc.Driver
</property>
<property name="connection.url"><!--指定连接数据库的路径-->
jdbc:jtds:sqlserver://localhost:1433/WebDB
</property>
<property name="connection.username">sa</property><!--指定连接数据库的用户名-->
<property name="connection.password">sa</property><!--指定连接数据库的密码-->
<property name="show_sql">true</property><!--当show_sql属性为true时表示在程序运行时在控制台输出SQL语句,默认为false,建议在调试程序时设为true,发布程序之前再改为false,因为输出SQL语句会影响程序的运行速度-->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="com/hou/actionForm/UsersForm.hbm.xml"/><!--指定持久化类映射文件-->
<mapping resource="com/hou/actionForm/FeedbackForm.hbm.xml"/>
<mapping resource="com/hou/actionForm/OrderForm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
public List selectInitOrder() {
session = sessionFactory.openSession();
tx = session.beginTransaction();
//System.out.println(tx);
String hql = "from OrderForm where initalAmount=2 order by dineTime desc";
List list = null;
try {
Query query = session.createQuery(hql);
list = query.list();
} catch (Exception e) {
System.out.println(e.getMessage());
}
tx.commit();
session.close();
return list;
}
我都恬出来了,大家帮忙给看看是那的问题.