日期:2014-05-20  浏览次数:20791 次

存储数据到数据库时出错
<%
  try
{
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  String url="jdbc:mysql://localhost/charge?user=root&password=123";
  Connection conn =DriverManager.getConnection(url);
  Statement smt=conn.createStatement();


String snumber = new String(request.getParameter("snumber").getBytes("ISO8859_1"),"GBK");
String sname = new String(request.getParameter("sname").getBytes("ISO8859_1"),"GBK");

  String sex = new String(request.getParameter("sex").getBytes("ISO8859_1"),"GBK");
  String grade = new String(request.getParameter("grade").getBytes("ISO8859_1"),"GBK");
  String classname = new String(request.getParameter("classname").getBytes("ISO8859_1"),"GBK");
  String sfsk = new String(request.getParameter("sfsk").getBytes("ISO8859_1"),"GBK");
  String sfxj = new String(request.getParameter("sfxj").getBytes("ISO8859_1"),"GBK");
  String amount = new String(request.getParameter("amount").getBytes("ISO8859_1"),"GBK");
  String sfqf = new String(request.getParameter("sfqf").getBytes("ISO8859_1"),"GBK");
  String qfamount = new String(request.getParameter("qfamount").getBytes("ISO8859_1"),"GBK");
   

String sql="insert into students (Snumber,Sname,sex,grade,classname,sfsk,sfxj,amount,sfqf,qfamount) values (?,?,?,?,?,?,?,?,?,?)";//插入数据
  PreparedStatement prepstmt =conn.prepareStatement(sql);
  prepstmt.setBytes(1,snumber.getBytes("GB2312"));
 prepstmt.setBytes(2,sname.getBytes("GB2312"));
prepstmt.setBytes(3,sex.getBytes("GB2312"));
prepstmt.setBytes(4,grade.getBytes("GB2312"));
prepstmt.setBytes(5,classname.getBytes("GB2312"));
prepstmt.setInt(6,Integer.parseInt(sfsk).byteValue());
prepstmt.setInt(7,Integer.parseInt(sfxj).byteValue());
prepstmt.setFloat(8,Float.parseFloat(amount).byteValue());
prepstmt.setInt(9,Integer.parseInt(sfqf).byteValue());
prepstmt.setFloat(10,Float.parseFloat(qfamount).byteValue());
  prepstmt.executeUpdate();

}
出错信息:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 16 in the jsp file: /savestudent.jsp
Generated servlet error:
Cannot invoke byteValue() on the primitive type int

An error occurred at line: 16 in the jsp file: /savestudent.jsp
Generated servlet error:
Cannot invoke byteValue() on the primitive type int

An error occurred at line: 16 in the jsp file: /savestudent.jsp
Generated servlet error:
Cannot invoke byteValue() on the primitive type float

An error occurred at line: 16 in the jsp file: /savestudent.jsp
Generated servlet error:
Cannot invoke byteValue() on the primitive type int

An error occurred at line: 16 in the jsp file: /savestudent.jsp
Generated servlet error:
Cannot invoke byteValue() on the primitive type float


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

org.apache.jasper.JasperException: Unable to compile class for JSP