Hi,
I'm checking for whether record exist in database or not. But it is not working. Though record exist, I never get the message.
***********************************************************************
Here is the table looks like.
EMPLID NAME EMAILID
1 Maruthi mbalmuri@hotmail.com
2 test test@test.com
3 test test@yahoo.com
********************************************************************
Here is the program.
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class updateDatabase extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html"
;
PrintWriter out = res.getWriter();
out.println("<HTML>"
;
out.println("<HEAD><TITLE>Display the records</TITLE></HEAD>"
;
out.println("<BODY>"
;
out.print("<code><pre>"
;
out.println("ID\tFirst Name\tLast Name\n"
;
// connect to database and query database
try
{
String myEmplid = req.getParameter("Emplid"
.trim();
String myName = req.getParameter("Name"
.trim();
String myEmail = req.getParameter("Email"
.trim();
boolean proceed = false;
// Using Sybase JCONNECT 5.2
Class.forName("com.sybase.jdbc2.jdbc.SybDriver"
;
Connection con =
DriverManager.getConnection("jdbc:sybase:Tds:server
ort#/dbase", username, password);
Statement stmt = con.createStatement( );
ResultSet rs = null;
String rsEmplid;
String recexist = "N";
rs = stmt.executeQuery("SELECT * FROM PS_PE"
;
while(rs.next())
{
rsEmplid = rs.getObject(1).toString().trim();
out.print("This is rsEmplid : " + rsEmplid + "\n"
;
out.print("This is myEmplid : " + myEmplid + "\n"
;
if (rsEmplid == myEmplid)
{
recexist = "Y";
out.print("Record Exist\n"
;
break;
}
} // end of while
out.print("Record Exist value " + recexist);
} // end of try
catch ( Exception e )
{
out.println( "An exception occurred." + e );
}
} // end doGet method
} // end of myConnection class
************************************************
here is the output.
ID First Name Last Name
This is rsEmplid : 1
This is myEmplid : 1
This is rsEmplid : 2
This is myEmplid : 1
This is rsEmplid : 3
This is myEmplid : 1
Record Exist value N
Thanks in advance
I'm checking for whether record exist in database or not. But it is not working. Though record exist, I never get the message.
***********************************************************************
Here is the table looks like.
EMPLID NAME EMAILID
1 Maruthi mbalmuri@hotmail.com
2 test test@test.com
3 test test@yahoo.com
********************************************************************
Here is the program.
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class updateDatabase extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html"
PrintWriter out = res.getWriter();
out.println("<HTML>"
out.println("<HEAD><TITLE>Display the records</TITLE></HEAD>"
out.println("<BODY>"
out.print("<code><pre>"
out.println("ID\tFirst Name\tLast Name\n"
// connect to database and query database
try
{
String myEmplid = req.getParameter("Emplid"
String myName = req.getParameter("Name"
String myEmail = req.getParameter("Email"
boolean proceed = false;
// Using Sybase JCONNECT 5.2
Class.forName("com.sybase.jdbc2.jdbc.SybDriver"
Connection con =
DriverManager.getConnection("jdbc:sybase:Tds:server
Statement stmt = con.createStatement( );
ResultSet rs = null;
String rsEmplid;
String recexist = "N";
rs = stmt.executeQuery("SELECT * FROM PS_PE"
while(rs.next())
{
rsEmplid = rs.getObject(1).toString().trim();
out.print("This is rsEmplid : " + rsEmplid + "\n"
out.print("This is myEmplid : " + myEmplid + "\n"
if (rsEmplid == myEmplid)
{
recexist = "Y";
out.print("Record Exist\n"
break;
}
} // end of while
out.print("Record Exist value " + recexist);
} // end of try
catch ( Exception e )
{
out.println( "An exception occurred." + e );
}
} // end doGet method
} // end of myConnection class
************************************************
here is the output.
ID First Name Last Name
This is rsEmplid : 1
This is myEmplid : 1
This is rsEmplid : 2
This is myEmplid : 1
This is rsEmplid : 3
This is myEmplid : 1
Record Exist value N
Thanks in advance