0

While running a login program, I am using Apache Tomcat 7.0, JDK 7, JRE 7, Eclipse Juno, and Oracle Database 10g Express Edition

 #login2.jsp
 <body>
    <div class="content">
        <ul>
            <li><a href="header1.jsp">Home</a></li>
            <li><a href="about.jsp">About Us</a></li>
            <li><a href="login.jsp">Booking</a></li>
            <li><a href="registration1.jsp">Registration</a></li>
            <li><a href="Gallery.jsp">Gallery</a></li>
            <li><a href="package1.jsp">Packages</a></li>
            <li><a href="logout.jsp">Logout</a></li>
        </ul>
    </div>
    <div class="right">
        <form action="Login2_back.jsp" method=post>
            <table>
                <tr>
                    <th>5 STAR HOTEL LOGIN</th>
                </tr>
                <tr>
                    <td>
                        <input type="text" name=n1 placeholder="User Id">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="password" name=n2 placeholder="Password">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" name="action" value="SIGN IN">
                    </td>

                </tr>
                <tr>
                    <td align=center><b>NEW USER</b></td>
                </tr>
                <tr>
                    <td>
                        <center><a href="registration1.jsp">REGISTER HERE</a> </center>
                    </td>
                </tr>
            </table>
            <tr>
                <td><a href="search.jsp">search</a>
                    <a href="update.jsp">update</a> </td>
            </tr>
        </form>
    </div>
    </div>
</body>

#Login2_back.jsp

<%@page import="java.sql.*" %>
<%@page import="pack.Dao" %>
<body>
    <% try { Connection con=Dao.dbconnect(); Statement stmt=con.createStatement(); 
String z=r equest.getParameter( "n1"); 
String x=r equest.getParameter( "n2"); 
ResultSet rs=stmt.executeQuery( "select userid,password from login where userid='"+z+ "' and password='"+x+ "'"); i
f(rs.next()) { %>
        <jsp:forward page="header1.jsp" />
    <% } else System.out.println( "Sorry Invalid  user and password"); %>
        <jsp:forward page="header1.jsp" />
    <% } catch(Exception e) {out.println(e);} %>
</body>

In cmd I connected to the database and I created a table login with `userid=sagar` and `password=sinha`

USERID               PASSWORD
-------------------- --------
sagar                sinha

after I commit;

But when I am going to login page using above code `login2.jsp`, using       `userid:sagar` and `password:sinha`, I got the error

java.sql.SQLException: ORA-00942: table or view does not exist 



#Dao.java
package pack;
import java.sql.Connection;
import java.sql.DriverManager;
public class Dao{
private static Connection con;
public static Connection dbconnect()
{
    try{

Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr,"");
    }catch (Exception e){
        System.out.println(e);
        //TODO: handle exception
    }
    return con;
 }
}

This is the connection i used to connect to the database oracle 10g express edition but when i am login it shows

java.lang.NullPointerException..

i did not get the error why it is coming everthing is correct in the program and successfully connected to the database . sqlplus /nolog then conn hr/hr,, connected cr

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

2 Answers2

0

This error is that you are making a query on a table or view that doesn't exists on your database schema,you have that login table?

mvlaicevich
  • 103
  • 1
  • 8
  • i created database table (login) using cmd ... but same error can u plz explain – user4801863 Apr 17 '15 at 17:02
  • yes, but this is an error on your database configuration. when you create the database, you create an schema, so you need to connect to that schema to find your table login. If you make the same query on cmd it works? – mvlaicevich Apr 17 '15 at 17:15
  • now i am getting the errore :java.lang.NullPointerException – user4801863 Apr 17 '15 at 18:38
  • can you update your question adding the log and you database config? – mvlaicevich Apr 17 '15 at 18:40
  • 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: localhost:1521:xe – user4801863 Apr 18 '15 at 13:55
  • try http://stackoverflow.com/questions/18192521/ora-12505-tnslistener-does-not-currently-know-of-sid-given-in-connect-descript – mvlaicevich Apr 18 '15 at 14:32
0

error is pretty straight forward. table does not exist, check your DAO class and confirm the connection string if it is connecting to the right database, then from there see if the login table exist

mel3kings
  • 8,857
  • 3
  • 60
  • 68