日期:2014-05-19  浏览次数:21057 次

为什么加了sql包还会出现PrepareStatement不能用
我用JSP连接oracle,在开头导入了java.sql.*,但是还是用不了PrepareStatement,错误信息如下:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 17 in the jsp file: /WEB-INF/tags/oracle.tag
PrepareStatement cannot be resolved to a type
14: out.print(e);
15: }
16: Connection conn;
17: PrepareStatement pstmt;
18: ResultSet rs;
19: try{
20:  


An error occurred at line: 23 in the jsp file: /WEB-INF/tags/oracle.tag
DatabaseMetadata cannot be resolved to a type
20:  
21: String URL="jdbc:oracle:thin:@localhost:1521:"+database;
22: conn=DriverManager.getConnection(URL,username,password);
23: DatabaseMetadata metadata=conn.getMetadata();
24: ResultSet rshead=metadata.getColumns(null,null,tablename,null);
25: int headCount=0;
26: result.append("<table border=1>");


An error occurred at line: 23 in the jsp file: /WEB-INF/tags/oracle.tag
The method getMetadata() is undefined for the type Connection
20:  
21: String URL="jdbc:oracle:thin:@localhost:1521:"+database;
22: conn=DriverManager.getConnection(URL,username,password);
23: DatabaseMetadata metadata=conn.getMetadata();
24: ResultSet rshead=metadata.getColumns(null,null,tablename,null);
25: int headCount=0;
26: result.append("<table border=1>");
不仅如此DatabaseMetadata和getMetadata()也不能用,这些不是sql包里面自带的吗?求高手解答!

------解决方案--------------------
PreparedStatement!!!!!你写错了兄弟,少了个d
DatabaseMetadata metadata=conn.getMetadata();这句也错了
DatabaseMetaData metadata=conn.getMetadata();

------解决方案--------------------
楼上的分析好像是正确的,如果是已经封装好的类或者是方法,如果是使用IDE开发工具可能会好一些,会提示错误
------解决方案--------------------
大哥,PreparedStatement,
多用用IDE,你要都自己打的话,你会死的很惨。。。
------解决方案--------------------
Connection对象 .PrepareStatement();(没有d)
==》得到的对象是PreparedStatement对象(有d)
这里不知道为什么会是这样,可能是BUG 也可能是其他原因 写代码的时候自己注意就好。
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html