473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL & Database: Selecting & Deleting a record

Can someone please tell me what's wrong with this instruction:

Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one:
Expand|Select|Wrap|Line Numbers
  1. String input = JOptionPane.showInputDialog("Who do you want to delete:");
  2. String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;
Sep 27 '07 #1
9 1868
madhoriya22
252 100+
Can someone please tell me what's wrong with this instruction:

Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one:
Expand|Select|Wrap|Line Numbers
  1. String input = JOptionPane.showInputDialog("Who do you want to delete:");
  2. String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;
Hi,
Is "Student Name" is column name in ur table ?
Sep 27 '07 #2
r035198x
13,262 8TB
Can someone please tell me what's wrong with this instruction:

Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one:
Expand|Select|Wrap|Line Numbers
  1. String input = JOptionPane.showInputDialog("Who do you want to delete:");
  2. String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;
Which database are you using?
The first statement should have quotes around Samuel if name is of type varchar or varchar2 depending on your database.
Your second statement should say delete from not delete * from.
Sep 27 '07 #3
Hi,
Is "Student Name" is column name in ur table ?
Firstly, thank you very much for responding to my problem. "Student Name" is indeed one of the column names in my table.
Sep 27 '07 #4
Which database are you using?
The first statement should have quotes around Samuel if name is of type varchar or varchar2 depending on your database.
Your second statement should say delete from not delete * from.
Thanks also for responding. The database I am using is called "School". How do I tell if the name is of type varchar or varchar2? Do I check directly in the database?
Sep 27 '07 #5
r035198x
13,262 8TB
Thanks also for responding. The database I am using is called "School". How do I tell if the name is of type varchar or varchar2? Do I check directly in the database?
I don't mean the name of your database in that sense. I mean is it MySQL, Oracle, Access, e.t.c. The structure of the sql depends on the database.
Sep 27 '07 #6
I don't mean the name of your database in that sense. I mean is it MySQL, Oracle, Access, e.t.c. The structure of the sql depends on the database.
It is Access. But in fact I've been working on this the whole day and I've virtually completed the whole thing. I have just 2 small problems left:
1. In the search method, I need to figure out how to display "Name not found" when the user inputs a name that's not in the database. I tried using the following code but it didn't work:
Expand|Select|Wrap|Line Numbers
  1. boolean inputRepeatedly = true;
  2. while (inputRepeatedly = true)
  3. {
  4. try
  5. {    
  6. String input1 = JOptionPane.showInputDialog("Please enter student's name");
  7. if (input1.length() == 0)
  8. {
  9. inputRepeatedly = false;
  10. }
2. How do you exit a submenu? i.e. The main menu pops up, user selects 'A) Insert name', user is repeatedly prompted to insert new records in the table until he wishes to cancel. I tried using the following code but it didn't work:
Expand|Select|Wrap|Line Numbers
  1. String input = JOptionPane.showInputDialog("Which name are you searching for?");
  2. rs = set.executeQuery("SELECT * FROM tblStudent WHERE StudentName = " + "'" + input + "'"); 
  3.  
  4. while (rs.next())
  5. {
  6. name = rs.getString("StudentName");
  7. if (name.equals(input)
  8. {
  9. System.out.println(name + " is present in the table");
  10. }
  11. else
  12. {
  13. System.out.println(name + " is not present");
  14. }
After these small problems are solved, I am completely done so thanks in abundance for helping.
Sep 27 '07 #7
Can someone please tell me what's wrong with this instruction:

Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one:
Expand|Select|Wrap|Line Numbers
  1. String input = JOptionPane.showInputDialog("Who do you want to delete:");
  2. String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;

Hi,
Some one gave good response. I am newly added in this group...

so u better to use string.Format method .. here we can avoid collisions

if u want assign any parameter to your query so better to create one format string based on that no need to take care of complicated built query

string.Format(" Select statements from table where col =place holer",col1,col2,...)

Ex:

String.Format("Select * FROM tblStudent WHERE StudentName ='{0}' ",StudentName);

SeleStat=String.Format("DELETE * FROM tblStudent WHERE StudentName = '{0}'",input);


write like this ..if column is string u have specify place holder in string otherwise no need strings(Invited commas)...

Note: columns should not take any gaps


ok

if it is helpful take it

otherwise ...take just kidding
bye
Sep 27 '07 #8
Hi,
Some one gave good response. I am newly added in this group...

so u better to use string.Format method .. here we can avoid collisions

if u want assign any parameter to your query so better to create one format string based on that no need to take care of complicated built query

string.Format(" Select statements from table where col =place holer",col1,col2,...)

Ex:

String.Format("Select * FROM tblStudent WHERE StudentName ='{0}' ",StudentName);

SeleStat=String.Format("DELETE * FROM tblStudent WHERE StudentName = '{0}'",input);


write like this ..if column is string u have specify place holder in string otherwise no need strings(Invited commas)...

Note: columns should not take any gaps


ok

if it is helpful take it

otherwise ...take just kidding
bye
Thank you very much - I will definitely take it!
Sep 27 '07 #9
r035198x
13,262 8TB
Have I suggest PreparedStatements yet?
Sep 27 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
3
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the...
7
by: Danny J. Lesandrini | last post by:
I know this has been discussed before, as I've seen the Google posts, but they all leave me with an unanswered question: Does my DAO code executed in the front end cause the back end to bloat?...
3
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm...
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
4
by: Lada 'Ray' Lostak | last post by:
Hello there, I am thinking how to solve another typical problem of online systems with combination of thin client... Imagine simple case, 2 users are going to edit 'same' datas. Both see on the...
25
by: Colin McKinnon | last post by:
Hi all, There's lots of DB abstraction layers out there, but a quick look around them hasn't turned up anything which seems to met my requirements. Before I go off and write one I thought I'd...
2
by: panki | last post by:
Hi Frnds As a college project, I am developing college admission software in VB.net using SQL server 7.0 as backend. Problem is that The Record is not Deleting from the Database. and It is showing...
1
by: solargovind | last post by:
Hi, I have one Form in which i have one subform also which links together by one common_id(Payment_id). When i display record, I need to delete Current record in both form & Table. I used the...
6
by: kfanarmy | last post by:
Hello; I am attempting to use a command button "Delete Current Assignment Record" on a form to delete a user-selected record from a table entitled "Registration" with Key field "Registration ID"....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.