【发布时间】:2012-04-20 04:52:58
【问题描述】:
当我试图运行这段代码建立连接时......这个错误来了
我正在使用 Apache-tomcat-7.0.8
org.apache.jasper.JasperException: Unable to compile class for JSP:
在以下行发生错误:1 in the jsp file: /test_conn.jsp
无法将连接解析为类型
1: <% Connection connection = null; try { // Load the JDBC driver String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName);
2:
3: // Create a connection to the database
4: String serverName = "URL";
我试过的代码:
<%@page import="java.sql.*,java.io.*,java.text.*,java.util.*" %>
<%@page import="java.util.*" %>
<%
Connection connection = null;
out.println("Before try");
try {
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
out.println("Entered try");
String url = "jdbc:oracle:thin:@:URL:port:sid";
String username = "usr";
String password = "pass";
connection = DriverManager.getConnection(url, username, password);
out.println("Successfully Connected");
}catch (SQLException e) {
out.println("Not Connected: "+ e.getMessage());
}
%>
【问题讨论】:
-
请包含更多代码...例如获取驱动程序连接。