java.sql.SQLException:ORA-00942:表或视图不存在

时间:2015-04-17 16:02:10

标签: java jsp oracle10g eclipse-juno

在运行登录程序时,我使用的是Apache Tomcat 7.0,JDK 7,JRE 7,Eclipse Juno和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;
 }
}

这是我用来连接数据库oracle 10g express edition的连接,但是当我登录时显示

  

显示java.lang.NullPointerException ..

我没有得到错误,为什么它在程序中正确并且成功连接到数据库。 sqlplus / nolog然后conn hr / hr ,, connected cr

2 个答案:

答案 0 :(得分:0)

这个错误是你在数据库模式上不存在的表或视图上进行查询,你有那个登录表吗?

答案 1 :(得分:0)

错误非常简单。表不存在,请检查您的DAO类并确认连接字符串是否连接到正确的数据库,然后从那里查看是否存在login