首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Class.forName(driverClass);

2013-09-11 
执行数据库存储过程出错,求解!!!!%@pagecontentTypetext/htmlcharsetgb2312%%@pageimportjava.s

执行数据库存储过程出错,求解!!!!
<%@ 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


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,"男");


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


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

Apache Tomcat/6.0.10

[解决办法]
conn.prepareCall();
[解决办法]
CallableStatement cs=Connection.prepareCall();
CallableStatement cs=Connection.prepareCall("{call p_insert(?,?,?,?,?,?,?,?,?,?)}");


这里重复的定义变量 cs 至少这里会报错的 。删除这句试一下..

我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行