servlet  
    public void addP(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SmartUploadException
{
    String filePath="\\upload";
    CPhotodao cpdao=new CPhotodao();
    CPhoto cpbean=new CPhoto();
    SmartUpload su=new SmartUpload();
    long maxsize=2*1024*1024;   //// 设置每个上传文件的最大值,为2MB
       try
       {
        su.initialize(this.getServletConfig(),request,response);
        su.setMaxFileSize(maxsize);  // 限制上传文件的大小
        su.setAllowedFilesList("jpg,gif,bmp");// 设置允许上传的文件类型
        su.upload();  // 上传文件
        String photoInfo=su.getRequest().getParameter("pinfomation");
        File file=su.getFiles().getFile(0);// 获取上传的文件,因为只上传了一个文件,所以可直接获取
            if(!file.isMissing())// 如果选择了文件
            {
             //filePath值(upload\\)+图片信息在数据表中的id字段值+“.”
             //+文件后缀名;最后生成例如“upload\12.bmp”路径
             String photoAddr=filePath+cpdao.queryMaxId();
                String time=su.getRequest().getParameter("ptime");
                cpbean.setStr_PAddr(photoAddr);
                cpbean.setStr_PAinfo(photoInfo);
                cpbean.setStr_PTime(time);
                boolean flag=cpdao.operationCPhoto("upload", cpbean);
                if(flag)
                {
                 try
                 {
                 file.saveAs(photoAddr,File.SAVEAS_VIRTUAL);
                 response.sendRedirect("admin/login.jsp");
                 }
                 catch(SmartUploadException e)
                 {
                 response.sendRedirect("photoupload.jsp");
                 e.printStackTrace();
                 }
                
                }
                else
                { System.out.println("保存文件失败!");
                  response.sendRedirect("photoupload.jsp");
                }
            }
            else
            { 
             System.out.println("请选择要上传的文件!");
             response.sendRedirect("photoupload.jsp");
            }
       }
       catch(java.lang.SecurityException e)
       {
        e.printStackTrace();
        response.sendRedirect("admin/photoupload.jsp");
       }
       catch(SmartUploadException e)
       {
         e.printStackTrace();
            response.sendRedirect("admin/photoupload.jsp");
       }
}

jsp 页面
  <TR>
    <TD class=forumrow width="50%" height=24 align="right">相片:</TD>
    <TD class=forumrowhighlight width="50%" height=24><input type="file" name="paddr" height="20"/><label style="color:red">&nbsp;(只能是.jpg,.bmp,.gif格式) </label></TD></TR>
  <TR>
    <TD class=forumrow width="50%" height=24 align="right">照片简介:</TD>
    <TD class=forumrowhighlight width="50%" height=24>
   <select name="pinfomation">
   <%
   try{
      CAlbumdao albumdao=new CAlbumdao();
      List list=albumdao.queryAlbum();
      if(list==null||list.size()==0)
      {
        System.out.println("<script>alert('没有数据!')</script>");
      }
      else 
      {
        for(int i=0; i<list.size();i++)
        {
           CAlbum album=(CAlbum)list.get(i);
    %>
       <option value="<%=album.getStr_Aname()%>" selected><%=album.getStr_Aname()%></option>
 <% }
      }
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
       %>
   </select>
    </TD>
  </TR>
   <tr>
    <TD class=forumrow height=24 align="right">上传时间:</TD>
    <TD class=forumrowhighlight height=24><input type="text" onfocus="showCalendar(this)" name="ptime" height="20" width="130" /></TD></TR>
 <tr align="center">
    <TD class=forumrow width="100%" colspan="2" height=24>
    <input type="submit" name="submit" value="确定" height="20"/> &nbsp;<input type="reset" name="reset" value="取消" height="20"></TD></TR>
  <TR>   数据库操作类
   public boolean operationCPhoto(String operate, CPhoto single)  
   {
   String sql=null;
   if(operate.equals("upload"))     //添加相片
   sql="insert into CPhoto values('"+single.getStr_PAddr()+"','"+single.getStr_PAinfo()+"','"+single.getStr_PTime()+"')";
   if(operate.equals("modify"))  //修改相片 
    sql="update CPhoto set PAddr='"+single.getStr_PAddr()+"',PAinfo='"+single.getStr_PAinfo()+"',PTime='"+single.getStr_PTime()+"' where Id='"+single.getInt_Id()+"'";
     if(operate.equals("delete"))   //删除相片
    sql="delete from CPhoto where Id='"+single.getInt_Id()+"'";    
   boolean flag=connection.executeUpdate(sql);
  return flag;    
   }错误是:
 信息: Server startup in 3450 ms
com.microsoft.sqlserver.jdbc.SQLServerException: 对象名  'Photo' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteQuery(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(Unknown Source)
at com.tools.dbcon.executeQuery(dbcon.java:76)
at com.dao.CPhotodao.queryMaxId(CPhotodao.java:145)
at com.servlet.CPHServlet.addP(CPHServlet.java:64)
at com.servlet.CPHServlet.doPost(CPHServlet.java:31)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
查询数据库失败!
   
           

解决方案 »

  1.   

    CPhotodao类中数据库查询的代码出了问题。
    请检查数据库中是否有Photo表。
      

  2.   

    sql="insert into CPhoto values('"+single.getStr_PAddr()+"','"+single.getStr_PAinfo()+"','"+single.getStr_PTime()+"')";表名是CPhoto 看看Photo到底是啥。
      

  3.   

    对象名 'Photo' 无效。 这个字段不存在啦 
      

  4.   

    sql语句的问题,检查一下sql语句,直接放在数据库中执行一下看是否正确
      

  5.   

    数据库连接的那个地方用到了'Photo' ,在数据库中找不到
      

  6.   

    你这个错和上传没关系 sql 错了
      

  7.   

    看看出错的SQL语句有没有那个PHOTO
      

  8.   

    Photo这个和数据库的不对应吧