Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-07-2008, 04:51 PM
Member
 
Join Date: Apr 2008
Posts: 1
Apple2 is on a distinguished road
Select Count
The following is sql code which checks for multiple “titles” with the same value (less than or equal to 3)

"SELECT count(*)<=3 FROM module WHERE title='?'".

I am trying to write a snippet of code that does a select count(*) from module where title=? (above code), and then if the result of that is 3=3 then do the INSERT (following code) else display an error message without inserting the record.

In simple terms the following code should only execute if the above code is true, else display a message without saving. can someone please help me out as I am kind of stuck.

PreparedStatement new_module = connection.prepareStatement("INSERT INTO module (room_number, module_code, title, provider, duration, time_slot, weekdays)"+ "VALUES(?,?,?,?,?,?,?)");

new_module.setString(1, request.getParameter("room_number"));
new_module.setString(2, request.getParameter("module_code"));
new_module.setString(3, request.getParameter("title"));
new_module.setString(4, request.getParameter("provider"));
new_module.setInt(5, 1);
new_module.setString(6, request.getParameter("time_slot"));
new_module.setString(7, request.getParameter("weekdays"));

new_module.executeUpdate();
connection.commit();
new_module.close();
response.sendRedirect("index.jsp");
connection.setAutoCommit(savedCommitValue);

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-29-2008, 10:02 AM
Member
 
Join Date: Dec 2007
Posts: 26
felixtfelix is on a distinguished road
hi,

Can u split the code into two something like this.

select count(1)no_of_rows from module where title like 'title_value'

rs=pstmt.executeQuery();

if(rs.next())
{
if(rs.getInt("no_of_rows")<=3)
{
--code to insert the second query
}else{
--code to show the error message
}
}

Regards,
Felix
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the count of all the lines in a file Java Tip java.io 0 04-06-2008 08:45 PM
Getting row count Java Tip Java Tips 0 02-11-2008 09:49 AM
how to count 2 inserts together? kim85 New To Java 0 01-20-2008 12:25 PM
making a count down timer using java saytri New To Java 3 12-29-2007 10:49 PM
Getting row count from executeQuery() Java Tip Java Tips 0 12-05-2007 03:31 PM


All times are GMT +3. The time now is 09:36 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org