Is this a proper way to check if a string exist in a db-column?
I don't know I am posting this in the right forum... anyway... I am trying to check if a string as an email address exist in a database with jsp (by returning true if the string exist). I have managed to do it but I am not sure if this is the best way.
As you see I have used stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" ) and checked by if rs.next() returning false or true. Here is my code in short format:
boolean strExist = false;
String myInputStr = request.getParameter("inputStr");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" );
if(rs.next())
strExist = true;
else
strExist = false;
return strExist;Is this the proper way of checking if a string exist in a db-column???
Thanks
I responded to your first thread [here.|http://forums.sun.com/thread.jspa?threadID=5374902]
Similar Messages
-
Is this a proper way of looking in a db-column?
I am trying to check if a string as an email address exist in a database with jsp (by returning true if the string exist). I have managed to do it but I am not sure if this is the best way.
As you see I have used stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" ) and checked by if rs.next() returning false or true. Here is my code in short format:
boolean strExist = false;
String myInputStr = request.getParameter("inputStr");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" );
if(rs.next())
strExist = true;
else
strExist = false;
return strExist;Is this the proper way of checking if a string exist in a db-column???
ThanksPreparedStatement is indeed the way to go.
Regarding to your code logic: this boolean strExist is less or more superfluous.
Leave it away and just doreturn rs.next();Or if you really, really need it then just dostrExist = rs.next();That said, do you properly close all resources? I see that you're immediately leaving the method block, leaving the statement and the resultset unclosed behind. This is resource leaking. The longer your application runs, the more you do so, your application will crash due to a shortage of DB resources. You need to close all the resources (connection, statement and resultset) as soon as possible. Do it in the finally block of the try block around SQLException in the same method.
I suggest to go through this tutorial to get some useful and proper ideas of how the database access stuff ought to be done: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html]. Good luck. -
Restating my issue / question...
When I send email from this iMac, there is a string of characters assigned. The characters are all the "alpha numeric" characters on the QWERTY key board. This only occurs when email is sent from this iMac. The issue does not manifest when using any other lap top or computer.
Hence, I have ruled out the issue is a yahoo mail matter.
Again, I can access the Yahoo mail account form multiple devices and send email without unintended assignment of character strings, but when I send wmail using this iMac, the issue happens everytime.
Characters are stacked verticaly in a column. It looks as if all characters (except function keys) are included in the string.
Any ideas?
GMcPlease read this whole message before doing anything.
This procedure is a diagnostic test. It won’t solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
Third-party system modifications are a common cause of usability problems. By a “system modification,” I mean software that affects the operation of other software — potentially for the worse. The following procedure will help identify which such modifications you've installed. Don’t be alarmed by the complexity of these instructions — they’re easy to carry out and won’t change anything on your Mac.
These steps are to be taken while booted in “normal” mode, not in safe mode. If you’re now running in safe mode, reboot as usual before continuing.
Below are instructions to enter some UNIX shell commands. The commands are harmless, but they must be entered exactly as given in order to work. If you have doubts about the safety of the procedure suggested here, search this site for other discussions in which it’s been followed without any report of ill effects.
Some of the commands will line-wrap or scroll in your browser, but each one is really just a single line, all of which must be selected. You can accomplish this easily by triple-clicking anywhere in the line. The whole line will highlight, and you can then copy it. The headings “Step 1” and so on are not part of the commands.
Note: If you have more than one user account, Step 2 must be taken as an administrator. Ordinarily that would be the user created automatically when you booted the system for the first time. The other steps should be taken as the user who has the problem, if different. Most personal Macs have only one user, and in that case this paragraph doesn’t apply.
Launch the Terminal application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
When you launch Terminal, a text window will open with a line already in it, ending either in a dollar sign (“$”) or a percent sign (“%”). If you get the percent sign, enter “sh” and press return. You should then get a new line ending in a dollar sign.
Step 1
Triple-click the line of text below to select it:
kextstat -kl | awk '!/com\.apple/{printf "%s %s\n", $6, $7}' | open -f -a TextEdit
Copy the selected text to the Clipboard by pressing the key combination command-C. Then click anywhere in the Terminal window and paste (command-V). A TextEdit window will open with the output of the command. Post the contents of that window, if any — the text, please, not a screenshot. You can then close the TextEdit window. The title of the window doesn't matter, and you don't need to post that. No typing is involved in this step.
Step 2
Repeat with this line:
{ sudo launchctl list | sed 1d | awk '!/0x|com\.(apple|openssh|vix)|org\.(amav|apac|cups|isc|ntp|postf|x)/{print $3}'; sudo defaults read com.apple.loginwindow LoginHook; } | open -f -a TextEdit
This time you'll be prompted for your login password, which you do have to type. Nothing will be displayed when you type it. Type it carefully and then press return. You may get a one-time warning to be careful. Heed that warning, but don't post it. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
Note: If you don’t have a login password, you’ll need to set one before taking this step. If that’s not possible, skip to the next step.
Step 3
launchctl list | sed 1d | awk '!/0x|com\.apple|org\.(x|openbsd)/{print $3}' | open -f -a TextEdit
Step 4
ls -1A /e*/mach* {,/}L*/{Ad,Compon,Ex,Fram,In,Keyb,La,Mail/Bu,P*P,Priv,Qu,Scripti,Servi,Spo,Sta}* L*/Fonts 2> /dev/null | open -f -a TextEdit
Important: If you formerly synchronized with a MobileMe account, your me.com email address may appear in the output of the above command. If so, anonymize it before posting.
Step 5
osascript -e 'tell application "System Events" to get name of every login item' | open -f -a TextEdit
Remember, steps 1-5 are all copy-and-paste — no typing, except your password. Also remember to post the output.
You can then quit Terminal. -
Mono voice over has 1 track only is this the proper way to do it?
My dialogue has 2 tracks (A1/A2), has well has my music (A3/A/4). My voice over, that was recorded in Mono is on just one track (A5), is this fine or should I have 2 tracks also for this voice over?
Thank you.That's not really a great way to handle mono audio, in my opinion. When you double audio tracks, you're literally doubling the audio; all your levels will be jacked up, because you're superimposing sound. What Shane said is what I understand to be the correct way — as far as there's ever a correct way to do anything — to handle mono audio. You pan your left and right stereo tracks to the left and the right, but you keep your mono tracks panned center (or automate the pan for things like foley effects on moving shots, stuff like that).
Among other things, this makes doing your final mix a lot easier, since you've got only the number of tracks you actually need. Every track you add creates more work when you finish your sound. -
Whats the best way to check weather a file exists online, or not?
Hi!
I need to show an Image File in my app which may have different sizes. _1.jpg, _2.jpg and so on.. If, for example, _2.jpg does not exist, I have to take _1.jpg.
So my question is: is there a better way instead of making/allocating a pic and asking pic != nil ?
thx!
alexHi Alex -
The subject line says "file exists online, or not?". Are you trying to check existence at a network site, or the local file system? I'll cover the local fs first, since that's the easiest. If you need to search a remote site, I think we'll need some more details.
Assuming an iPhone project (not specified, but your usual topic), NSFileManager will probably be all you need unless the files are localized and/or in the application bundle, in which case you'll want NSBundle. For example, say you're storing all the jpg's in the user's cache directory:
#define MAXFN 5
// return nil or the path to the file with the highest numeric suffix
- (NSString)getPathForBestFile:(NSString)baseName extension:(NSString*)ext {
NSString *bestFilePath = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
// locate the user's cache directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
NSLog(@"cacheDirectory=%@", cacheDirectory);
// loop through file names with numeric suffixes
for (int i = 1; i <= MAXFN; i++) { />/
NSString *fileName =
[NSString stringWithFormat:@"%@_%d.%@", baseName, i, ext];
NSString *filePath =
[cacheDirectory stringByAppendingPathComponent: fileName];
NSLog(@" filePath=%@", filePath);
if ([fileManager fileExistsAtPath:filePath])
bestFilePath = filePath;
return bestFilePath;
If you need to use NSBundle, see pathForResource:ofType:. If you need to determine the existence of a file at a network site, please give us some details about the kind of server and how much you'll know about the possible file locations.
Hope that helps!
- Ray -
BC4J datatags: is this the best way to do this?
In my BC4J JSP application, in the DataTableComponent.jsp, I want to check
if a property exists on the view object. This is the best way I could come
up with:
String PropertyValue =
(String)dsBrowse.getApplicationModule()
.findViewObject(dsBrowse.getViewObjectName())
.getProperty("PropertyName");
Is this the proper way to get at a view property? Seems like it should be more straightforward.
Also, does an instance of the ViewImpl class get automatically created when the DataSource tag is used or do you have to specifically instantiate it if you want to use a client method on the view?
Thanks,
SteveYou can do:
String propVal = dsBrowse.getRowSet().getViewObject().getProperty("PropName");You do not have to instantiate any classes on your own to accomplish this. -
Proper way to use data throughout a class?
I know global variables aren't a thing in c#, as that goes against the rules.
So I have a couple of functions and subroutines (pardon my vocabulary if it isn't canon). I use a simple array to transfer data back and forth. Is this the proper way to do this? As in most efficient, readable, and expandable?
class Program
static void Main()
bool[] MotorPosition = new bool[4];
MotorPosition[0] = true;
MotorPosition[1] = false;
MotorPosition[2] = true;
MotorPosition[3] = false;
while (true)
MotorPosition = UpdateMotorPosition(MotorPosition);
DisplayMotorPosition(MotorPosition);
System.Threading.Thread.Sleep(64);
static bool[] UpdateMotorPosition(bool[] MotorPosition)
bool[] NewMotorPosition = new bool[4];
for (int x = 0; x < 4; x = x + 1)
NewMotorPosition[x] = !MotorPosition[x];
return NewMotorPosition;
static void DisplayMotorPosition(bool[] MotorPosition)
string CombinedDisplay = null;
for (int x = 0; x < 4; x = x + 1)
CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
Console.WriteLine(CombinedDisplay);
Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN ForumsAbsolutely amazing! I learn something new every day. I wonder when programming will cease to amaze me.
using your example jdweng, I was able to add a counter to your code and move the motor position to the test class; as well as add another motor by instancing the class again!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
class Program
static int Main(string[] args)
Test test = new Test();
test.Initialize(); //Assigns initial value to MotorPosition
Test test2 = new Test();
test2.Initialize(); //Assigns initial value to MotorPosition
while (true)
if (test.MotorUpdateCount == 40) Console.ReadLine(); //pauses at 40 to make it easy to see output upto that point
if (test.MotorUpdateCount > 1000) return -1; //ends program
test.MotorPosition = test.UpdateMotorPosition(test.MotorPosition); //updates motor 1 position
test.DisplayMotorPosition(test.MotorPosition); //displays motor 1 position
if (test.MotorUpdateCount > 20) //at count 20, engages motor 2
test2.MotorPosition = test2.UpdateMotorPosition(test2.MotorPosition); //updates motor 2 position
test2.DisplayMotorPosition(test2.MotorPosition); //displays motor 2 position
System.Threading.Thread.Sleep(128); //slows the loop down to reasonable speed
public class Test
public int MotorUpdateCount = 0;
public bool[] MotorPosition = new bool[4];
public void Initialize()
MotorPosition[0] = true;
MotorPosition[1] = false;
MotorPosition[2] = true;
MotorPosition[3] = false;
public bool[] UpdateMotorPosition(bool[] MotorPosition)
bool[] NewMotorPosition = new bool[4];
for (int x = 0; x < 4; x = x + 1)
NewMotorPosition[x] = !MotorPosition[x];
MotorUpdateCount = MotorUpdateCount + 1;
return NewMotorPosition;
public void DisplayMotorPosition(bool[] MotorPosition)
string CombinedDisplay = null;
for (int x = 0; x < 4; x = x + 1)
CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
Console.WriteLine(CombinedDisplay);
Console.WriteLine(MotorUpdateCount.ToString());
Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums -
What's the best/fastest way to check for existance of a userobject
We are developing an Addon in VB.NET.
I think there are two ways to check if a table exists:
1) usertableMD.GetByKey(tablename)
2) orecordset.DoQuery("SELECT * FROM sysobjects WHERE ...)
I would like to use the first way, but is the GetByKey fast and how much will the call "System.Runtime.InteropServices.Marshal.ReleaseComObject(usertableMD) " slow down ?I personnaly use GetByKey
I think that opening a recordset is not the optimized SAP solution, and anyway, you'll have to release the recordset
Private Function UserTableExists(pst_TableName) As Boolean
Dim dsa_UserTablesMD As UserTablesMD
Dim dbo_ReturnCode As Boolean
dsa_UserTablesMD = msa_Company.GetBusinessObject(BoObjectTypes.oUserTables)
dbo_ReturnCode = dsa_UserTablesMD.GetByKey(pst_TableName)
System.Runtime.InteropServices.Marshal.ReleaseComObject(dsa_UserTablesMD)
Return dbo_ReturnCode
End Function -
How to check if database/table exists in MYSQL
I am writing a program which accesses databases in MYSQL, is there any way to check if the databases exists on the MYSQL server and if not create one && to check if a table exists and create one of if it does not
OK, found out that as special permissions needed to create databases I assume it cannot be done via my app but how about Tables
-
Has anyone else who uses AT&T as their carrier been told if you cannot access your voicemail through your iPhone that there is no way to check your voicemails? This is an issue since I had to send my phone in for repair. Thank you
You received incorrect information from AT&T. You can indeed access your voicemail without your iPhone.
Call AT&T at (800) 331-0500 (assuming you're in the U.S.). This is a 24 hour a day, 7 day a week number. Ask them how to access your voicemail. Normally, you would just do this by dialing your number from another phone, typing "*" once your voicemail recording starts, and entering your password. You don't know your password, so it's probably the last four digits of your phone number or perhaps the seven - or ten-digit phone number. Let the AT&T person tell you. -
I have Boot Camp running on a separate HD (not a partition on my Mac drive). I would like to partition the PC HD to have a multi boot PC. What is the proper way to do this? How do I select which partition to start the PC?
I have Boot Camp running on a separate HD (not a partition on my Mac drive). I would like to partition the PC HD to have a multi boot PC. What is the proper way to do this? How do I select which partition to start the PC?
-
I have been filling up my internal memory on my laptop after years of video editing. I now want to export all this footage to an external hard drive. What is the proper way to do this.
Are the videos being stored in iMovie or another application? Have you exported/shared the video? If the video is in iMovie what version of iMovie are you using? Give as much info as possible, and you may also want to post the question in the iLife section of this forum since more people with video skills will be reading the iLife/iMovie threads.
-
Proper way to pass 'this' to an anonymous listener
I have added a button to copy some information to the clipboard. Instead of a class-level actionPerformed() method I am using an anonymous listener:
JButton jb = new JButton("Copy QE");
jb.setBackground(bgc);
jb.setForeground(Color.lightGray);
jb.setToolTipText("copy the information below to the clipboard");
final HelpBox that = this;
jb.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringSelection ss = new StringSelection(that.toString());
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents(ss, SIHwheel.logBox);
});It seems to be working fine. I am wondering, though, is the final declaration of that the proper way? Is there a better overall methodology?A common approach is to encapsulate the logic into a method on the enclosing class. Then, the listener would just call the method:
private void someMethod() {
// init the JButton...
jb.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateClipboard();
private void updateClipboard()
StringSelection ss = new StringSelection(this.toString());
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents(ss, SIHwheel.logBox);
} -
What's the proper way to update this table field?
I've got a table with a field of TOTAL. There's a linked table with a field of AMOUNT. There's one main table record to multiple linked records. I'd like to replace the TOTAL with the sum of Amount for each link. I'm
having a hard time setting up an update query to do that. Any suggestions?
ajwThe proper way is almost certainly not to store the totals in a column in a table at all, but to compute them in an aggregating query, e.g. to return the sum of transaction amounts per customer:
SELECT CustomerID, SUM(Amount) AS TotalAmount
FROM Transactions
GROUP BY CustomerID;
Storing aggregated values is only necessary if these can legitimately be amended independently of the values from which they are computed. This is not out of the question, but is rarely the case.
Ken Sheridan, Stafford, England -
I am getting pop ups on safari and firefox lately and am worried I may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?
Please review the options below to determine which method is best to remove the Adware installed on your computer.
The Easy, safe, effective method:
http://www.adwaremedic.com/index.php
If you are comfortable doing manual file removals use the somewhat more difficult method:
http://support.apple.com/en-us/HT203987
Also read the articles below to be more prepared for the next time there is an issue on your computer.
https://discussions.apple.com/docs/DOC-7471
https://discussions.apple.com/docs/DOC-8071
http://www.thesafemac.com/tech-support-scam-pop-ups/
Maybe you are looking for
-
Adobe Download Assistant not working after bluescreen
I like to get the trial for Photoshop Elements 10 but the ADA is broken: Under Windows 7 I already used the ADA to download and install Adobe Premiere 10 successfully a week ago. Then I tried to get Adobe Photoshop Elements 10 but my system crashed w
-
The Mysteriously Appearing Photos That Were In The Trash Bin
Hello; I have a conventional digital camera that connects to my mac USB and downloads my photos onto my desktop. I frequently toss out photos I do not want. Last night I tossed out a bunch of my photos and emptied the trash bin. But just a minute ago
-
hi i am adding new field to my existing package which is char(10). getting this error: [Flat File Destination [139]] Error: Data conversion failed. The data conversion for column "MEMBER_ID" returned status value 4 and status text "Text was truncated
-
How to Identify Swept Transactions?
Is there a way to identify the transactions that were swept from last month?
-
Error trying to run an executable Jar file
Hi, I know a million people have asked this before. In the past 5 hours I have waded thru a dozen questions-answers-FAQs that were no help. So if anyone is willing to help a stupid person her is my problem: I developed a java program using the eclips