Solved

Database and Servlets (searching and restriction)

Posted on 2002-03-28
3
143 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 50 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

820 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