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

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>Home</li>
<li>About Us</li>
<li>Booking</li>
<li>Registration</li>
<li>Gallery</li>
<li>Packages</li>
<li>Logout</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>REGISTER HERE </center>
</td>
</tr>
</table>
<tr>
<td>search
update </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

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?

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

Related

jsp forward tag is not working in jsp

I have made a login page and a forward tag is not working it creates error which i can not able to find out.
I uses access database and after clicking sign in button it will check, if user is already registerd then page should forward next page but it does not so.
Here is my code:
<form action="login.jsp" method="get">
<table>
<tr></tr>
<td><br>
<label>EmailID:</label>
</td>
<td>
<input type="text" name="emailid" maxlength="50" size="30">
</td>
<tr></tr>
<td><br>
<label>Password:</label>
</td>
<td>
<input type="password" name="passwordid" maxlength="50" size="30">
<p>
</p>
</td>
<tr></tr>
<td></td>
<td><input type="submit" value="sign in"></center></td>
<%
try
{
String existemail="registration",existpass="12345";
ResultSet rs, rs1;
String emailid1=request.getParameter("emailid");
String passwordid1=request.getParameter("passwordid");
if(emailid1.length()!=0 && passwordid1.length()!=0)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:collegep");
Statement st = conn.createStatement();
rs=st.executeQuery("select password from collge where
email='"+emailid1+"'");
while(rs.next())
{
existpass= rs.getString(1);
}
if(existpass.equals(passwordid1))
{
<jsp:forward page=
"afterlogin.html" />
}else
{ %> invalid combination of email and password<%
}
}
else
{` %>
<div id="error">all field must be filled.</div>
<%
}
}
catch(Exception e){}
%>
Please try changing from:
<jsp:forward page:
to:
<jsp:forward page=
It seems like you used inappropriate Scriplet Tags(<% %>)..close scriptlet end tag(%>) above ur <jsp:forward page="afterlogin.html"/>
All java code should be in Scriplet Tag only..and html code outside of it..make this changes

Session servlet does not work on drop down menu jsp

This is my coding for order.jsp, a form for customer to insert order and I use session.menus to display option menu in a HTML input element from database. I already connect to database using jdbcutility.java, where I put sql statement to connect my servlet with database and its working for login but not for this session.
<form class="form-horizontal" method="post" action="InsertOrderServlet">
<center>
<table border="10" cellpadding="20" cellspacing="20">
<thead>
<tr>
<th colspan="2"><h2 style="line-height: 3;" >Order Food</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td><br><br>Food</br></br></td>
<td>
<br><br>
<div class="col-lg-9">
<select class="form-control" name="menuName">
<c:forEach items="${sessionScope.menus}" var="currentmenu" varStatus="loop">
<option><c:out value="${currentmenu.foodName}" /></option>
</c:forEach>
</select>
</div>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="quantity" required/></td>
</tr>
<tr style="line-height: 10;" >
<td> <button class="btn btn-primary" type="reset" >Cancel</button></td>
<td > <button type="submit" class="btn bt primary">Submit</button></td>
</td>
</tr>
</tbody>
</table>
</center>
</form>
getMenuServlet.java
//select all from menu
try {
ResultSet rs = jdbcUtility.getPSSelectMenu().executeQuery();
while (rs.next()) {
menu = new Menu();
menu.setId(rs.getInt("menuid"));
menu.setfoodName(rs.getString("foodName"));
menu.setImage(rs.getString("image"));
menu.setPrice(rs.getDouble("price"));
//put into arraylist
menus.add(menu);
}
}
catch (SQLException ex)
{
}
//put into sessions
session.setAttribute("menus", menus);
jdbcutility.java
String sqlValidateLogin = "Select username,password from customer where username=? and password=?";
psInsertLogin = con.prepareStatement(sqlValidateLogin);
String sqlInsertOrder = "INSERT INTO orderfood(menuName, quantity) " + "VALUES(?, ?)";
psInsertOrder = con.prepareStatement(sqlInsertOrder);
String sqlSelectAllMenu ="SELECT * FROM menu";
psSelectAllMenu = con.prepareStatement(sqlSelectAllMenu);
String sqlSelectAllOrder ="SELECT * FROM orderfood";
psSelectAllOrder = con.prepareStatement(sqlSelectAllOrder);
This keep occurring, how do I fix this?
image blank
Make sure the JSP is allow access session.
<%# page session="true" %>
To use core JSTL, make sure the following code is included.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

how to get value using model and scriptlets

I am creating a table in JSP in which i am displaying some values using hard code.
i want to display those value using scriptlets and model. Someone help me how to do that?
<tr>
<td>Automobile</td>
<td>11-JUN-2015</td>
<td>10-FEB-2016</td>
<td>Cars and bikes</td>
</tr>
Getting values from the database:
<%rst=stmt.executeQuery("select * from auto_details");%>
Sample Html Table:
<html>
<body>
<center>
<h2>AutoList</h2>
<table border="1" cellspacing="0" cellpadding ="0">
<tr>
<td><b>S.No</b></td>
<td><b>Date</b></td>
<td><b>typeofvichele</.b></td>
</tr>
<%
int no=1;
while(rst.next()){
%>
<tr>
<td><%=no%></td>
<td><%=rst.getString("date")%></td>
<td> <%=rst.getString("typeofvichele")%> </td>
</tr>
<%
no++;
}
rst.close();
stmt.close();
con.close();
%>
</table>
</center>
</body>
</html>

login page using session in jsp

I've created a login environment using jsp. index.jsp, login.jsp. I take username and password from database. If user name and password matches with the database it does login process perfectly. When user give wrong name or password it shows a error message invalid name or passwordand redirect to the login page. Nothing's wrong, but I am facing a problem when I login first. The place where the error message is shown after submitting wrong name or password that place is showing null.
Why null is showing?
Below is my code
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Example</title>
</head>
<body>
<form action="login.jsp" method="post">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2" align ="left">Login Here</th> <h5><%=request.getAttribute("errorMessage")%> </h5>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
login.jsp
<%# page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from member where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
response.sendRedirect("success.jsp");
} else {
request.setAttribute("errorMessage", "Invalid user or password");
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
%>
You can use this in your index.jsp
<% if ((String) request.getAttribute("errorMessage") != null) {%>
<h3 style="color: red;"><%=(String) request.getAttribute("errorMessage")%></h3>
<%
}
%>
Instead of this
<%=request.getAttribute("errorMessage")%>
please check condition before showing error, if request parameter is null then it should not be rendered else it would be rendered, modify you code according to below snippet
<thead>
<tr>
<th colspan="2" align ="left">Login Here</th>
<h5>
<%if(request.getParameter("errorMessage")!=null){%>
<%=request.getParameter("errorMessage")%><%}%>
</h5>
</tr>
</thead>
The errorMessage attribute will not be available in request for the first time. Kindly check for a null and then display the message.
<%=request.getAttribute("errorMessage")%>
The below piece of code could help you.
<tr>
<th colspan="2" align ="left">Login Here</th>
<h5>
<%
String errorMsg = request.getAttribute("errorMessage");
if (errorMsg != null) {
%>
<%=errorMsg%>
<%
}
%>
</h5>
</tr>
As errorMessage attribute is null in the request when you load it first time, so you are getting null. You need to add null check for it. You can do this way
<th colspan="2" align ="left">Login Here</th>
<% if (request.getAttribute("errorMessage") != null) {
out.println("<h5>" + request.getAttribute("errorMessage") + "</h5>");
}%>
Correct your code in login.jsp
write session.setAttribute("errorMessage", "Invalid user or password");
instead of request.setAttribute("errorMessage", "Invalid user or password");
..
null message show because of this.

Getting exception : java.lang.NullPointerException on my jsp page

i am posting my code in which i am getting the java.lang.NullPointerException exception.
<%# page contentType="text/html;charset=UTF-8" %>
<%# page errorPage="myError.jsp?from=customers.jsp" %>
<%# page import="java.sql.*" %>
<html>
<head>
<title>Insurance Quoting System</title>
</head>
<body>
<basefont face="Arial">
<!-- JSP Declarations -->
<%! ResultSet rs = null; %>
<!-- JSP Scriptlet -->
<%
try {
Class.forName("com.mysql.mysql.Driver");
Connection db = DriverManager.getConnection("jdbc:mysql://localhost:3306/quoting","root","root");
Statement s = db.createStatement();
rs = s.executeQuery("select * from customer");
}
catch (Exception e) {
// For now, just report the error to the system log
System.out.println(e.toString());
}
%>
<!-- Template text -->
<table width="550" border="0" align="center">
<tr>
<td bgcolor="#006633">
<div align="center">
<font size="6" color="#FFFFFF">
<b>Insurance Quoting System</b>
</font>
</div>
</td>
</tr>
<tr>
<td>
<p> </p>
<p> </p>
<p align="center"><b>Customers</b></p>
<table width="290" border="0" align="center">
<%
try {
while (rs.next()) {
%>
<!-- JSP Expressions used within template text -->
<tr>
<td width="20"><%= rs.getInt(1) %></td>
<td width="70"><%= rs.getString(2) %></td>
<td width="70"><%= rs.getString(3) %></td>
<td width="40">
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=edit">
edit
</a>
</td>
<td width="40">
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=delete">
delete
</a>
</td>
<td width="40">
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=newQuote">
new quote
</a>
</td>
</tr>
<%
}
}
catch (SQLException e) {
// For now, just report the error to the system log
System.out.println(e.toString());
}
%>
</table>
</td>
</tr>
<tr>
<td>
<p> </p>
<p align="center">New Customer</p>
</td>
</tr>
</table>
</body>
</html>
i am making one jsp page its giving some error java.lang.NullPonterException on my jsp page pls tell me the ans if any one have .
The only thing I can think of that is causing this is that you are catching an exception in your first try-catch block and then trying to use the ResultSet as if it's been initialized, but it's still null, so you are getting NPE. Check to see if your Database operations work correctly.

Categories