• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

run over a data base and check for equals values

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic