下記、InsertServlet.javaをコンパイルしようとしたら
シンボリが見つかりません。
Schedule info=new Schedule();
^ ^
と出ます。
因みに、Schedule.javaはコンパイル済みで同じ
階層のフォルダに配置しています。
//(InsertServlet.java)
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InsertServlet extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
request.setCharacterEncoding("Windows-31J");
Schedule info=new Schedule();
info.setTitle(request.getParameter("title"));
info.setSdate(request.getParameter("sdate_year")+"-"+request.getParameter("sdate_month")+"-"+request.getParameter("sdate_day"));
info.setStime(request.getParameter("stime_hour")+":"+request.getParameter("stime_minute"));
info.setMemo(request.getParameter("memo"));
info.insertInfo();
response.sendRedirect("insert.jsp");
}
}
//ここまで
//ここから
//(Schedule.java)
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class Schedule implements Serializable{
private String sid;
private void setSid(String sid){this.sid=sid;}
public String getSid(){return this.sid;}
private String title;
public void setTitle(String title){this.title=title;}
public String getTitle(){return this.title;}
private String sdate;
public void setSdate(String sdate){this.sdate=sdate;}
public String getSdate(){return this.sdate;}
private String stime;
public void setStime(String stime){this.stime=stime;}
public String getStime(){return this.stime;}
private String memo; public void setMemo(String memo){this.memo=memo;} public String getMemo(){return this.memo;} public int insertInfo(){ int result=0; Connection db=null; PreparedStatement ps=null; try{ Context context=new InitialContext(); DataSource ds=(DataSource)context.lookup("java:comp/env/jdbc/Jsp10"); db=ds.getConnection(); ps=db.prepareStatement("insert into schedule(title,sdate,stime,memo)values(?,?,?,?)"); ps.setString(1,this.title); ps.setString(2,this.sdate); ps.setString(3,this.stime); ps.setString(4,this.memo); result=ps.executeUpdate(); ps.close(); db.close(); }catch (NamingException e){ e.printStackTrace(); }catch(SQLException e){ e.printStackTrace(); }finally{ try{ if(ps!=null){ps.close();} if(db!=null){db.close();} }catch(SQLException e){ e.printStackTrace(); } } return result; }
}
回答1件
あなたの回答
tips
プレビュー