Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check for record not found on database using javascript

Status
Not open for further replies.

CdnRebel

Programmer
Apr 5, 2003
39
CA
This is the code I have, but I haven't incorporated the record not found check in properly. How should it be done?

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:eek:dbc:DoctorLookUp","","");
Statement stat = conn.createStatement();
rs = stat.executeQuery("Select first_name, middle_initial, last_name, phone_number from Doctors Where attending_physician_id='"+physician_id+"'");
if not found then raise exception '' doctor id not found, re-enter id '', doctors;
msg = "Physician%20Id%20not%20found%20in%20the%20doctors%20database,%20please%20re-enter";
response.sendRedirect("/examples/jsp/DocDelete1.jsp?msg="+msg);
end if;

while(rs.next()){

att_physician_id=physician_id;
firstname=rs.getString("first_name");
middleinitial=rs.getString("middle_initial");
lastname=rs.getString("last_name");
phonenumber=rs.getString("phone_number");
 
This is not Javascript code. You should post this on the Java forum.

There's always a better way. The fun is trying to find it!
 
This code is from my javascript program and response.sendRedirect is javascript, not java. I'm using javascript because I want to display the information I retrieve from the database to the user.
 
Let me see if I understand...

you are embedding values in the url address for
javascript to read on the client side with
the "(examples/jsp/DocDelete1.jsp?msg="+msg)";
Then you want to use window.location.search
to parse this info after you unescape it???

Is this the general idea???

2b||!2b
 
Yes, I am embedding values in the url address for javascript to read on the client side with the "(examples/jsp/DocDelete1.jsp?+msg)";. That works fine.
You lost me when you got to the part about using "window.location.search to parse this info after I unescape it". The only part of that code that I am questioning is how to properly code the "if not found then raise exception". The rest of the code works fine. I can access the database and retrieve my data and I can return an error message (with the response.sendRedirect) to my calling .jsp program which I guess you could say has been set up to parse the message. The window.location.search part, I'm not familiar with. The calling program is able to retrieve the message properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top