当我试图运行这段代码来建立连接时......这个错误来了
我正在使用 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());
}
%>