-2

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>
user2340915
  • 11
  • 2
  • 3
  • 7
  • 2
    What's unclear about that error message? –  May 09 '13 at 10:34
  • Coding is right, error is somewhere created during making database and its connectivity. Whole project is running right, editor can enter questions, admin can see results, operator can do its work. Candidate logs in, he can edit his details, but when he go to test page and select a type of test. That test don't open. And give the mentioned error. So explain me where is error and how to remove it? – user2340915 May 09 '13 at 14:36
  • You are logging in with the wrong username or password, simple as that. Btw: loading the JDBC driver and establishing the connection **inside** a JSP scriptlet is very, very bad coding style. Read up on connection pools. And even worse: you should never, ever, under no circumstances use the `SYSTEM` account from within your (Web)application. –  May 09 '13 at 14:44
  • For database, it is right username and password"system","12345". Explain me solution. This bad coding style is working in whole project. Error is not in coding. Its in some logical thing needed during database making. – user2340915 May 09 '13 at 15:11
  • "*Error is not in coding*" - yes it is. Your *code* is sending username and password to the database - and it's sending the wrong one, otherwise Oracle wouldn't complain. So it's your *code* that is wrong. And **stop using the `system` account**! –  May 09 '13 at 15:33
  • Ok, right, I was looking another program with same name. But now the error is java.sql.SQLException: Exhausted Resultset. And right coding is given above. Can you help in it? – user2340915 May 09 '13 at 15:58
  • possible duplicate of [Oracle JDBC : invalid username/password (ora-01017)](http://stackoverflow.com/questions/8435234/oracle-jdbc-invalid-username-password-ora-01017) – brandizzi Apr 24 '14 at 22:14

1 Answers1

0

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.

igr
  • 3,409
  • 1
  • 20
  • 25
  • In getConnection function, username and password is right. Checked in sqlplus, password is right. Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","12345"); It is also right. For password, it is entered in numeric format i.e. 111111. So it is also right. – user2340915 May 09 '13 at 09:23
  • Password is in varchar2, so any word can come in field of password. – user2340915 May 09 '13 at 09:30
  • Please add the code you're using to connect to the database, as well as the *complete* username/password/connection string. Also add the sqlplus example session you use to verify your connection. And please add it to the original post and not as a comment. – Frank Schmitt May 09 '13 at 10:40
  • Used localhost - you do run your java code on the same machine where is Oracle server? – igr May 09 '13 at 12:08
  • Yes, both are on same machine, coding and oracle. – user2340915 May 09 '13 at 14:38