Solved

Database and Servlets (searching and restriction)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

929 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

11 Experts available now in Live!

Get 1:1 Help Now