1.datel类型的数据的获取与转换:注:为java.util.Date
(1)_Impl.java conn = DBOperator.getConnection();
String sql = "insert into competitor values(?,?,?,?,?,?,?,?)";
java.sql.Date sqlDate = new java.sql.Date(ct.getBirth().getTime());
System.out.println("sqlDate="+sqlDate);
pst = conn.prepareStatement(sql);
pst.setInt(1, ct.getId());
pst.setString(2, ct.getUsername());
pst.setString(3, ct.getPassword());
pst.setString(4, ct.getRealname());
pst.setInt(5, ct.getMatchage());
pst.setDate(6, sqlDate );
pst.setString(7, ct.getAddress());
pst.setString(8, ct.getSex());
(2).__.java(servlet)
int id = Integer.parseInt(request.getParameter("id"));
String username = request.getParameter("username");
String password = request.getParameter("password");
String realname= request.getParameter("realname");
int matchage=Integer.parseInt(request.getParameter("matchage"));
String birth = request.getParameter("birth");
String sex= request.getParameter("sex");
String address= request.getParameter("address");
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
Date dirths=null;
try {
dirths = sim.parse(birth);
CompetitorManager sm = new CompetitorManagerImpl();
Competitor ct = new Competitor();
ct.setId(id);
ct.setUsername(username);
ct.setPassword(password);
ct.setRealname(realname);
ct.setMatchage(matchage);
ct.setBirth(dirths);
ct.setAddress(address);
ct.setSex(sex);
boolean flag = sm.add(ct);
if(flag == true)
2.单选框按钮的数据的获取。
(1)_.jsp
性 别<input type="radio" value="男" name="sex" >男 <input type="radio" value="女" name="sex">女<br><br>
(2). int id = Integer.parseInt(request.getParameter("id"));
String username = request.getParameter("username");
String password = request.getParameter("password");
String realname= request.getParameter("realname");
int matchage=Integer.parseInt(request.getParameter("matchage"));
String birth = request.getParameter("birth");
String sex= request.getParameter("sex");
String address= request.getParameter("address");
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
Date dirths=null;
try {
dirths = sim.parse(birth);
System.out.println("dirths==="+dirths);
CompetitorManager sm = new CompetitorManagerImpl();
Competitor ct = new Competitor();
ct.setId(id);
ct.setUsername(username);
ct.setPassword(password);
ct.setRealname(realname);
ct.setMatchage(matchage);
ct.setBirth(dirths);
ct.setAddress(address);
ct.setSex(sex);
boolean flag = sm.add(ct);