Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Database and Servlets (searching and restriction)

Posted on 2002-03-28
3
Medium Priority
?
164 Views
Last Modified: 2013-11-24

How do you restric users to enter one id such that if the other user enters the same id there will be a message telling him that that id has been entered.

How do you entered a record into two different tables after the user has entered once

0
Comment
Question by:wbmorapedi
  • 3
3 Comments
 
LVL 3

Accepted Solution

by:
msterjev earned 200 total points
ID: 6904538
Before you enter the id into the table check if it exists against the table with following SQL statement:

int id=5;
boolean present=false;
resultset=statement.executeQuery("SELECT * FROM Table1 WHERE id='+id;
if(resultset.next())
     present=true;
resultset.close();

if(!present)
{
     statement.execute("INSERT INTO Table1 VALUES.......");
     statement.execute("INSERT INTO Table2 VALUES.......");
}
statement.close();
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6904541
I forgot that you want message :-)

int id=5;
boolean present=false;
resultset=statement.executeQuery("SELECT * FROM Table1 WHERE id='+id;
if(resultset.next())
    present=true;
resultset.close();

if(!present)
{
    statement.execute("INSERT INTO Table1 VALUES.......");
    statement.execute("INSERT INTO Table2 VALUES.......");
}
else
{
    System.out.println("The requested ID is already present;please inter another one!");
}
statement.close();
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6904859
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
A solution for Fortify Path Manipulation.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question