Solved

Database and Servlets (searching and restriction)

Posted on 2002-03-28
3
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding multiple JVM environments to RedHat 6 7 79
eclipse console opening separately 2 46
Problem to Alipay 10 93
Java pass by reference 3 70
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

738 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