报错: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
(有两个类,一个是登录类,一个是登录的处理类)
主要代码:(登录类)
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=utf-8");
PrintWriter out=response.getWriter();
out.print("
}
处理类的代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.getWriter().print("aaaa");
String id=request.getParameter("id");
String password=request.getParameter("password");
Connection ct=null;
ResultSet rs=null;
PreparedStatement ps=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:merlin","SCOTT","tiger");
ps=ct.prepareStatement("selcet * from U where id=? and password=?");
ps.setObject(1, id);
ps.setObject(2, password);
rs=ps.executeQuery();
if(rs.next())
{
request.getRequestDispatcher("/MainFrame").forward(request, response);
}else{
request.getRequestDispatcher("/Login").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
网上有改listener.ora的说法,我改了还是不行啊
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\app\Merlin\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\app\Merlin\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
)
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(ORACLE_HOME = D:\app\Merlin\product\11.2.0\dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = D:\app\Merlin
oracle账户的问题或者配置的文件,拒绝连接。
http://blog.csdn.net/shen_xiao_wei/article/details/5729463
把"jdbc:oracle:thin:@127.0.0.1:1521:merlin","SCOTT","tiger"里127.0.0.1改成localhost或者自己的IP试下
ORA-12505 是tns配置错误,你可以看一下
ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:merlin","SCOTT","tiger");
怀疑你的实例应该是orcl,试试这个
ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","SCOTT","tiger");