Solved

Database and Servlets (searching and restriction)

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now