Can someone please tell me what's wrong with this instruction: - String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one: - String input = JOptionPane.showInputDialog("Who do you want to delete:");
-
String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;
9 1872
Can someone please tell me what's wrong with this instruction: - String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one: - String input = JOptionPane.showInputDialog("Who do you want to delete:");
-
String sql = "DELETE * FROM tblStudent WHERE Student Name = " + input;
Hi,
Is "Student Name" is column name in ur table ?
Can someone please tell me what's wrong with this instruction: - String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one: - String input = JOptionPane.showInputDialog("Who do you want to delete:");
-
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.
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.
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?
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.
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: - boolean inputRepeatedly = true;
-
while (inputRepeatedly = true)
-
{
-
try
-
{
-
String input1 = JOptionPane.showInputDialog("Please enter student's name");
-
if (input1.length() == 0)
-
{
-
inputRepeatedly = false;
-
}
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: - String input = JOptionPane.showInputDialog("Which name are you searching for?");
-
rs = set.executeQuery("SELECT * FROM tblStudent WHERE StudentName = " + "'" + input + "'");
-
-
while (rs.next())
-
{
-
name = rs.getString("StudentName");
-
if (name.equals(input)
-
{
-
System.out.println(name + " is present in the table");
-
}
-
else
-
{
-
System.out.println(name + " is not present");
-
}
After these small problems are solved, I am completely done so thanks in abundance for helping.
Can someone please tell me what's wrong with this instruction: - String sql = "SELECT * FROM tblStudent WHERE Student Name = Samuel";
...And this one: - String input = JOptionPane.showInputDialog("Who do you want to delete:");
-
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,col 2,...)
Ex:
String.Format(" Select * FROM tblStudent WHERE StudentName ='{0}' ",StudentNa me);
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
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,col 2,...)
Ex:
String.Format(" Select * FROM tblStudent WHERE StudentName ='{0}' ",StudentNa me);
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!
Have I suggest PreparedStateme nts yet?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 boxes and saving to the database at the end with the 'Submit' command button.
Is it possible to save the changes as the checkboxes are clicked? I...
|
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 list boxes'). Users can add and remove items from the
list boxes.
When the users are adding and removing items, the list boxes are single
|
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?
(May also substitute UPDATE and/or DELETE queries for DAO code.)
I was just brought on to a project with Access 97 where the all data is
kept on...
|
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 using cascade delete. When I use a continuous form
and a record is deleted, Access provides a warning that there are
related records, do you want...
|
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 this function using
select-for-update (or equivalent) in order to get a row-level lock (and
thus less contention) while maintaining the function...
| |
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 'screen' the same, after they started
edit them. First one changes datas and submit changes (sucessfully).
Database (set tables -...
|
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 ask here if anyone knows of such a
beast...
I want some code where I present an array of data, and the corresponding
primary key and let the code...
|
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 Error. I used same code for MS Access database and the record is being deleted. Please Help me.
My code is...
|
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 following code to delete.
---
Dim response
Dim strsql As String
response = MsgBox("Are you sure to Delete?", vbYesNo, "Payment Alteratiion")
If...
|
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".
I am using a combo box named "Select Task" that displays info from three tables to enable the user to select a record. The form's data source is...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |