Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run over a data base and check for equals values

 
yossi avisror
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankes for your help daniel
well i changed the the PrintWriter string like your's and it workes the answer i get is 'good' but what i want to get with the PrintWriter is a new html page and i can't get it and i dont know what is my mistake.
(i also changed the if command)
[This message has been edited by yossi avisror (edited May 26, 2001).]
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ExamSet extends HttpServlet
{
private String teacherid;
private String examsubject;
private static Connection connection;
private Statement checkIfLoged;

public void init()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch(Exception e)
{
System.out.println("Registering the Driver was failed");
}
try
{
connection = DriverManager.getConnection
("jdbc:mysql://localhost:3306/ExamDB");
}
catch(Exception exception)
{
System.out.println("Connection with the DataBase failed");
exception.printStackTrace();
System.exit(1);
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
Exams exam =new Exams(connection);
res.setContentType("text/html");
teacherid=req.getParameter("teacherid");
examsubject=req.getParameter("subject");
*********************************************
try
{
checkIfLoged=connection.createStatement();
ResultSet rs=checkIfLoged.executeQuery("SELECT id FROM students WHERE id="+teacherid);
if (rs.equals(teacherid))
{ PrintWriter outt=res.getWriter();
outt.println(" wrong ");
outt.close();
}
else
{
PrintWriter outtt=res.getWriter();
outtt.println(" wrong ");
outtt.close();
}
*********************************************
try
{
exam.addNewExam(teacherid,examsubject);
}
catch(SQLException sql){}
}
catch(Exception e){}
}
}

[This message has been edited by yossi avisror (edited May 26, 2001).]
[This message has been edited by yossi avisror (edited May 26, 2001).]
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What results are you getting now?
runtime error, WRONG, ...
Dan
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I notice your teacher id is a string. If you are comparing two strings you must consider CASE and Padding.
Ex: Jones != JONES --- might consider and UPPER function
EX: Jones(sp)(sp)(sp) != JONES --- consider TRIM or PAD
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic