当前位置: 代码迷 >> J2EE >> Class.forName(driverClass);  
  详细解决方案

Class.forName(driverClass);  

热度:475   发布时间:2016-04-22 03:43:57.0
执行数据库存储过程出错,求解!!!!
<%@ page contentType="text/html;charset=gb2312"%>  
<%@ page import="java.sql.*"%>  
<html>  
<body>  
<%
String driverClass="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driverClass);  
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=company";  
//statement查询操作  
String user="sa";  
String password="";  
Connection conn=DriverManager.getConnection(url,user,password);  
Statement stmt=conn.createStatement();  
String sql="select * from employee";  
ResultSet rs=stmt.executeQuery(sql); 

CallableStatement cs=Connection.prepareCall();
CallableStatement cs=Connection.prepareCall("{call p_insert(?,?,?,?,?,?,?,?,?,?)}");
cs.setString(1,"E0021");
cs.setString(2,"吴华");
cs.setString(3,"男");
cs.setString(4,"业务");
cs.setString(5,"职员");
cs.setString(6,"1993-04-12");
cs.setString(7,"1966-08-02");  
cs.setString(8,"50000");  
cs.setString(9,"13767654743");
cs.setString(10,"北京市");
int num=cs.executeUpdate(); 

   
while(rs.next()) {
%>  

   
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
您的第三个字段内容为:<%=rs.getString(3)%><br>
您的第四个字段内容为:<%=rs.getString(4)%><br>
您的第五个字段内容为:<%=rs.getString(5)%><br>
您的第六个字段内容为:<%=rs.getString(6)%><br>
您的第七个字段内容为:<%=rs.getString(7)%><br>
您的第八个字段内容为:<%=rs.getString(8)%><br>
您的第九个字段内容为:<%=rs.getString(9)%><br>
您的第十个字段内容为:<%=rs.getString(10)%>
<p>  
<%}%>  
<%out.print("数据库操作成功,恭喜你");%>  
<%rs.close();  
stmt.close();  
conn.close();  
%> 



错误日志如下:
HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

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

An error occurred at line: 17 in the jsp file: /MyChun.jsp
The method prepareCall(String) in the type Connection is not applicable for the arguments ()
14: String sql="select * from employee";  
15: ResultSet rs=stmt.executeQuery(sql); 
16: 
17: CallableStatement cs=Connection.prepareCall();
18: CallableStatement cs=Connection.prepareCall("{call p_insert(?,?,?,?,?,?,?,?,?,?)}");
19: cs.setString(1,"E0021");
20: cs.setString(2,"吴华");


An error occurred at line: 18 in the jsp file: /MyChun.jsp
Duplicate local variable cs
15: ResultSet rs=stmt.executeQuery(sql); 
16: 
17: CallableStatement cs=Connection.prepareCall();
18: CallableStatement cs=Connection.prepareCall("{call p_insert(?,?,?,?,?,?,?,?,?,?)}");
19: cs.setString(1,"E0021");
20: cs.setString(2,"吴华");
21: cs.setString(3,"男");


An error occurred at line: 18 in the jsp file: /MyChun.jsp
Cannot make a static reference to the non-static method prepareCall(String) from the type Connection
  相关解决方案