error : java.sql.SQLException: ORA-01017: invalid username/password; logon denied

user2340915 picture user2340915 · May 9, 2013 · Viewed 16.3k times · Source

I entered 10 questions in database, with their answers. I started project, I logged in candidate id. After that I gave admit id, it was accepted. After that I tried to open this page(this page is meant to open the test page, which will open questions), and I got error message - java.sql.SQLException: ORA-01017: invalid username/password; logon denied As far I know, there is no error in coding of project. So I had not posted the coding. Error is somewhere in database connectivity. (I had seen other topics with this error, but not found help).

 {   if(minutes==0 && seconds==0)
    {
       alert('Oops ! ! Time up '+
            'Test Submitted Successfully');
        VerbForm.submit();
    }
seconds=60;
minutes--;
window.setTimeout("timer()", 1000 );   

}
}


" name="forma"> Time Remaining:
" style="border:0px solid white; background: #F0EFE2">:" style="border:0px solid white; background: #F0EFE2"> timer();
        </div>



  <div id="site_content">

  <div id="content">

    <%
    try{
    int i=1;
    Random rand =new Random();
    int newrand=rand.nextInt(9);
    session.setAttribute("verbrandom",String.valueOf(newrand));
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","java","12345");
     String admitid=session.getAttribute("admitid").toString();
    int aid=Integer.parseInt(admitid); 
    PreparedStatement ps1=con.prepareStatement("select verbkey from result where admitid=?");
    ps1.setInt(1,aid);
    ResultSet rs1=ps1.executeQuery();
    rs1.next();
    if(rs1.getInt("verbkey")==1)
                   {
                    response.sendRedirect("AlreadyExam.jsp");
                   }
           else
           {
    PreparedStatement ps=con.prepareStatement("select * from verbal where qid>? order by qid");
    ps.setInt(1,newrand);
    ResultSet rs=ps.executeQuery();
        while(rs.next() && i<=10)
        {
    %>

    <form action="VerbalResult.jsp" align="left" name="VerbForm">



        <P><b><%=i%>. <%=rs.getString("question")%></b><BR><BR>

" value="<%=rs.getString("option1")%>">  A.  <%=rs.getString("option1")%>  " value="<%=rs.getString("option2")%>">  B.  <%=rs.getString("option2")%>

" value="<%=rs.getString("option3")%>">  C.  <%=rs.getString("option3")%>  " value="<%=rs.getString("option4")%>">  C.  <%=rs.getString("option4")%>

             <%
                i++;
                     } rs.close();
                        ps.close();        
                        } 
                     con.close();
                     rs1.close();
                     ps1.close();


    }
    catch(NullPointerException e)
                          {
        response.sendRedirect("CandidateLogin.jsp");
    }
            %>

<p><input style="padding-top: 25px; font: 100% arial; border: 1px solid; width: 170px; margin: 0 0 0 212px; height: 33px; padding: 2px 0 3px 0;cursor: pointer;background: #7D0F0F; color: #FFF;"  class="submit" type="submit" onclick="DoneTest()" name="TestButton" value="Submit Verbal Test"></p>

Answer

igr picture igr · May 9, 2013

Check your username and password provided into getConnection function. Verify this username and password from other tool (like sqlplus).
If username and password are ok, verify if alias is correct (if using JDBC OCI) or that host:port/serviceName is correct (or host:port:sid).

For passwords, be sure to use upper case / lower case letters as needed.