当前位置: 代码迷 >> J2EE >> sql2000查询语句的,想完成修改功能,该怎么解决
  详细解决方案

sql2000查询语句的,想完成修改功能,该怎么解决

热度:236   发布时间:2016-04-22 02:43:15.0
sql2000查询语句的,想完成修改功能

我建的表PID是主键,自动+1的,根据PID查询报的错是 java.sql.SQLException: Invalid column name PID.

  我试过了,映射文件里是PID,报的是Invalid column name PID,改成pID,报的就是Invalid column name pID,映射文件在下面,
at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:964)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getInt(JtdsResultSet.java:968)
at mapping.ProductMapping.mapping(ProductMapping.java:12)
at mapping.ProductMapping.mapping(ProductMapping.java:1)
at javabean.JdbcTemplate.query(JdbcTemplate.java:58)
at dao.ProductDAO.findById(ProductDAO.java:172)
at com.controller.FindByIDProductServlet.doGet(FindByIDProductServlet.java:31)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

这是映射 public Product mapping(ResultSet rs) throws SQLException{
Product product=new Product(rs.getInt("PID"),
rs.getString("ProName"), rs.getInt("Length"),
rs.getInt("Wide"), rs.getInt("Height"),  
rs.getInt("Weight"),rs.getString("Eterprise"),
rs.getInt("Issend"),rs.getInt("FormID"));
return product;

}
修改获取PID
<td><a href="FindByIDProductServlet?PID=<%=product.getPID() %>">修改</a></td>

跳转到的Servlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int PID=Integer.parseInt(request.getParameter("PID"));
ProductDAO productDAO=new ProductDAO();
Product product=productDAO.findById(PID);
request.setAttribute("product", product);
request.getRequestDispatcher("admin/chanpin/updateProduct.jsp").forward(request, response);

}

调用的方法
public Product findById(int PID) {
String sql = "select ProName, Length, Wide,Height," +
"Weight,Eterprise,FormID from Product where PID= "+PID;
Product product = null;
try {
product = (Product) jdbcTemplate.query(sql, new ProductMapping()).get(0);
} catch (SQLException e) {

e.printStackTrace();
}
return product;


还有一个和上面的大同小异,报的是列名ID无效,

servlet代码:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int ID=Integer.parseInt(request.getParameter("ID"));
EterpriseDAO eterpriseDAO=new EterpriseDAO();
Eterprise eterprise=eterpriseDAO.findAll(ID);
request.setAttribute("eterxiugai", eterprise);
request.getRequestDispatcher("/admin/qiye/updateEterprise.jsp").forward(request, response);


调用的方法 public Eterprise findAll(int ID) {
Eterprise eterprise = null;  
String sql = "select * from Product where ID= "+ID;

try{
eterprise= (Eterprise)jdbcTemplate.query(sql,new EterpriseMapping()).get(0);
  相关解决方案