[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

query syntax

Posted on 2012-08-28
9
Medium Priority
?
542 Views
Last Modified: 2012-09-04
I was going through following link.

http://www.roseindia.net/tutorial/java/poi/insertExcelFileData.html

I have not understtod below query syntax

int k=stat.executeUpdate("insert into login(username,password) value('"+username+"','"+password+"')");

>>login(username,password)
 is login is the name of the table with columns names username,password in the paranthesis?

I need to build select query similar way.

 Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1600 total points
ID: 38343283
>> is login is the name of the table with columns names username,password in the paranthesis?

Yes.

>>Any ideas, suggestions,

Use bind variables.

I'm not a Java person but there are a couple of examples here:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:19398056075583

I'm sure if you look around there are more.
0
 
LVL 7

Author Comment

by:gudii9
ID: 38343366
executeUpdate I got as 1 but when I went to toad to check the record it is not there
int k=stat.executeUpdate("insert into login(username,password) value('"+username+"','"+password+"')");



Do I need to give any commit statement in the java code explicitly. Please advise
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38343394
>>Do I need to give any commit statement in the java code explicitly.

It is good coding practice to physically commit or rollback and not rely on the 'default' action.

>> I got as 1

I don't know what this means. If it is a return code, does a 1 mean successful?  Remember I'm not a Java guy.
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 7

Author Comment

by:gudii9
ID: 38343411
I was checking below command

select count(*) into <variable_1> from dual where exists (select null from XYX_Table where col1=<variable_2> and col2=<variable_3>);


I am getting 1 even when record is there or not from java program.

And getting 0 from toad always. Please advise
0
 
LVL 21

Assisted Solution

by:Amitkumar P
Amitkumar P earned 400 total points
ID: 38344052
whenever you use the count() only the field in the select clause, it will always return a single row.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38344203
follow-up question posted here for that 2nd question:
http://www.experts-exchange.com/Programming/Languages/Java/Q_27845679.html
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38344205
the "1" (or "0") is normally the number of rows affected.
0
 
LVL 7

Author Comment

by:gudii9
ID: 38355056
>>whenever you use the count() only the field in the select clause, it will always return a single row.

can you please elaborate on this. I am not clear on this




I have gone through the link
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:19398056075583

I have not clearly understood about bind variables and their significance with prepared statements

>>>

Followup   June 8, 2004 - 3pm Central time zone:

I was pointing out that in this sequence of code:

     39     PreparedStatement pstat =
     40     conn.prepareStatement
     41     ("Select this is not really SQL now is it?" );
     42
     43     pstat.setString( 1, ename_like );
     44     ResultSet rset = pstat.executeQuery();
     45



the statement is not parsed by the server, in fact not sent to the server, until line 44 -- so we
do in fact have access to the bind variable values at parse time.



Please advise
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38355121
>>I have not clearly understood about bind variables and their significance with prepared statements

Using bind variables reduces the risk of SQL Injection and Hard parsing.  Don't try to understand the entire thread since it is talking about bind variable peeking.  That isn't what I was eanting you to take from it.  Just the Bind variables themselves.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question