当前位置: 代码迷 >> Java Web开发 >> Only a type can be imported. com.mysql.jdbc.Driver resolves to a package解决方案
  详细解决方案

Only a type can be imported. com.mysql.jdbc.Driver resolves to a package解决方案

热度:12450   发布时间:2013-02-25 21:19:33.0
Only a type can be imported. com.mysql.jdbc.Driver resolves to a package
mysql连接数据库代码如下:
<%@ page contentType="text/html; charset=gb2312" %> 
<%@ page language="java" %> 
<%@ page import="com.mysql.jdbc.Driver" %> 
<%@ page import="java.sql.*" %> 
<% 
//驱动程序名 
String driverName="com.mysql.jdbc.Driver"; 
//数据库用户名 
String userName="root"; 
//密码 
String userPasswd="123"; 
//数据库名 
String dbName="pressrealse"; 
//表名 
String tableName="character"; 
//联结字符串 
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
Connection connection=DriverManager.getConnection(url); 
Statement statement = connection.createStatement(); 
String sql="SELECT * FROM "+tableName; 
ResultSet rs = statement.executeQuery(sql); 
//获得数据结果集合 
ResultSetMetaData rmeta = rs.getMetaData(); 
//确定数据集的列数,亦字段数 
int numColumns=rmeta.getColumnCount(); 
// 输出每一个数据值 
out.print("id"+" "); 
out.print("name"+" "); 
out.print("price"); 
out.print("<br>"); 
while(rs.next()) { 
out.print(rs.getString(1)+" "); 
out.print(rs.getString(2)+" "); 
out.print(rs.getString(3)); 
out.print("yuan RMB"); 
out.print("<br>"); 

out.print("<br>"); 
out.print("数据库操作成功,恭喜你"); 
rs.close(); 
statement.close(); 
connection.close(); 
%>
每次都提示:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 11 in the generated java file
Only a type can be imported. com.mysql.jdbc.Driver resolves to a package
这是什么问题?

------解决方案--------------------------------------------------------
jar包重复
------解决方案--------------------------------------------------------
Only a type can be imported

这句很关键!
------解决方案--------------------------------------------------------
谢谢,受教了
  相关解决方案