源码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%--
使用JDBC连接Oracle数据库
使用MLDN数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:MLDN" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
Statement stmt = null ;
%>
<%
try
{
Class.forName(DBDRIVER) ;
// 连接时必须填写用户名及密码
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
// 创建表的SQL语句
String sql = "CREATE TABLE mldntab (name varchar(20))" ;
stmt = conn.createStatement() ;
stmt.executeUpdate(sql) ;
stmt.close() ;
conn.close() ;
}
catch(Exception e)
{
out.println(e) ;
}
%>
用JSP连接Oracle失败,错误信息如下:
java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was: 127.0.0.1:1521:MLDN