int flag = pstmt.executeUpdate(); if (flag != 0){ response.sendRedirect("lookup.jsp"); }else{System.out.println("执行失败");} 我要检查t1是否越界,try catch应该怎么写啊?谢谢啦,我自己写的不对啊
public int getRecordCount(String sql) { Connection localConnection = DataSource.getConnection(); Statement localstmt = null; ResultSet rs = null;
我写进去tomcat服务器报错了:org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 32 in the jsp file: /operator.jsp Illegal modifier for the variable getRecordCount; only final is permitted 29: if (flag != 0){ 30: response.sendRedirect("lookup.jsp"); 31: }else{System.out.println("执行失败");} 32: public int getRecordCount(String sql) { 33: 34: Connection localConnection = DataSource.getConnection(); 35: Statement localstmt = null; An error occurred at line: 32 in the jsp file: /operator.jsp Syntax error on token "(", ; expected 29: if (flag != 0){ 30: response.sendRedirect("lookup.jsp"); 31: }else{System.out.println("执行失败");} 32: public int getRecordCount(String sql) { 33: 34: Connection localConnection = DataSource.getConnection(); 35: Statement localstmt = null; 后面还有一大堆啊
An error occurred at line: 32 in the jsp file: /operator.jsp Illegal modifier for the variable getRecordCount; only final is permitted 重点关注这句:报错 第32行,你把你的这个方法的代码贴出来吧 另外,使用try catch去捕获异常,并在catche模块e.printStackTrace(); 例如: try{ //你的SQL相关处理 }catch(Exception e){ e.printStackTrace(); //你的异常处理,比如提示信息给页面展示
你可以对你的程序有可能出错的地方进行try catch捕获!
String t2 = request.getParameter("T2");
String t3 = request.getParameter("T3");
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/mobile";
Connection conn = DriverManager.getConnection(url,"root","123");
String sql = "INSERT INTO user(id,name,psw) VALUES(?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1,t1);
pstmt.setString(2,t2);
pstmt.setString(3,t3);
int flag = pstmt.executeUpdate();
if (flag != 0){
response.sendRedirect("lookup.jsp");
}else{System.out.println("执行失败");}
我要检查t1是否越界,try catch应该怎么写啊?谢谢啦,我自己写的不对啊
Statement localstmt = null;
ResultSet rs = null;
int count = 0;
try {
localstmt = localConnection.createStatement();
rs = localstmt.executeQuery(sql);
while(rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
// 捕获异常
e.printStackTrace();
} finally {
DataSource.close(rs);
DataSource.close(localstmt);
DataSource.close(localConnection);
}
return count;
}
Illegal modifier for the variable getRecordCount; only final is permitted
29: if (flag != 0){
30: response.sendRedirect("lookup.jsp");
31: }else{System.out.println("执行失败");}
32: public int getRecordCount(String sql) {
33:
34: Connection localConnection = DataSource.getConnection();
35: Statement localstmt = null;
An error occurred at line: 32 in the jsp file: /operator.jsp
Syntax error on token "(", ; expected
29: if (flag != 0){
30: response.sendRedirect("lookup.jsp");
31: }else{System.out.println("执行失败");}
32: public int getRecordCount(String sql) {
33:
34: Connection localConnection = DataSource.getConnection();
35: Statement localstmt = null;
后面还有一大堆啊
另外,你的主键"id"是数值还是字符串?要插入字符串?
Illegal modifier for the variable getRecordCount; only final is permitted
重点关注这句:报错
第32行,你把你的这个方法的代码贴出来吧
另外,使用try catch去捕获异常,并在catche模块e.printStackTrace();
例如:
try{
//你的SQL相关处理
}catch(Exception e){
e.printStackTrace();
//你的异常处理,比如提示信息给页面展示
}