在netbeans中连接oracle数据库

时间:2016-04-15 13:45:50

标签: java oracle jdbc

我正在尝试将oracle数据库连接到netbeans。我遵循https://netbeans.org/kb/docs/ide/oracle-db.html中给出的指示。 我完成了给出网站的所有步骤。 但是当我尝试使用servlet页面连接数据库时,我收到了一个错误。

错误如下,

  

错误发生:侦听器拒绝连接时出现以下错误:ORA-12505,TNS:侦听器当前不知道连接描述符中给出的SID客户端使用的连接描述符是:localhost:1521:XE [kavindu on KAVINDU ]

我不知道,接下来会做什么,

我的servlet代码如下所示,

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String customer_id = request.getParameter("customer_id");
    String f_name = request.getParameter("f_name");
    String l_name = request.getParameter("l_name");
    String mobile_no = request.getParameter("mobile_no");
    String address = request.getParameter("address");

 try {
         //loading driver 

        Class.forName("oracle.jdbc.driver.OracleDriver");

        //creating connection with the database 
        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE [kavindu on KAVINDU]","kavindu","123456");

        PreparedStatement ps = con.prepareStatement("insert into COMPACT_DISK values(?,?,?,?,?)");


        ps.setString(1, customer_id);
        ps.setString(2, f_name);
        ps.setString(3, l_name);
        ps.setString(4, mobile_no);
        ps.setString(5, address);
        int i = ps.executeUpdate();

 if (i > 0) {
            //out.println("Compact disk successfully inserted");
            RequestDispatcher d = request.getRequestDispatcher("new.html");
            d.forward(request, response);
        }
    } catch (ClassNotFoundException | SQLException | ServletException | IOException se) {
        out.println("Error Occured : \n" + se.getLocalizedMessage());
    }
}

 @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

  */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

1 个答案:

答案 0 :(得分:0)

检查数据库SID是否正确,我认为这是问题所在。