AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pass Values to Java

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Ryan Johnson
Guest





PostPosted: Thu Nov 11, 2004 11:12 pm    Post subject: Pass Values to Java Reply with quote



I am now able to connect to an Oracle database and run a query and
have it return values and now I would like to use a variable in the
select statement. Right now I am running the Java program from a
command prompt by typing in

c:java databaseconn

I would like to pass values to it somehow and I see I might be able to
do it like this:

c:java databaseconn 123456

Where 123456 is going to be the values passed to the Java program.
How can I actually pass the values to Java in the SQL statement?

Snipit Code from the program:

public void connect(){
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection("jdbc:oracle:thin:@0.0.0.0:1521:TTT",
"user", "password");
if (conn!=null){
System.out.println("connection made");
Statement stmt = null;
ResultSet rset = null;

stmt = conn.createStatement();

// Execute Statement to get product Information from
the Database
rset = stmt.executeQuery(" SELECT log_field1 " +
" FROM " + "transaction where log_field5 =
'596612'");

while (rset.next())
System.out.println(rset.getString ("log_field1"));

// Close Result Set and Statement
rset.close();
stmt.close();
}
else{
System.out.println("connection NOT made");
}
}
Back to top
Hal Rosser
Guest





PostPosted: Fri Nov 12, 2004 5:29 am    Post subject: Re: Pass Values to Java Reply with quote



In the main method of your databaseconn class, you'll see that (String[]
args) is the argument of main.
You can access the "123456" (the arg you specified) in main by referencing
args[0].
use args[0] when building your SQL string ..

HTH

"Ryan Johnson" <ryan.johnson (AT) arrisi (DOT) com> wrote

Quote:
I am now able to connect to an Oracle database and run a query and
have it return values and now I would like to use a variable in the
select statement. Right now I am running the Java program from a
command prompt by typing in

c:java databaseconn

I would like to pass values to it somehow and I see I might be able to
do it like this:

c:java databaseconn 123456

Where 123456 is going to be the values passed to the Java program.
How can I actually pass the values to Java in the SQL statement?

Snipit Code from the program:

public void connect(){
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");

conn =
DriverManager.getConnection("jdbc:oracle:thin:@0.0.0.0:1521:TTT",
"user", "password");
if (conn!=null){
System.out.println("connection made");
Statement stmt = null;
ResultSet rset = null;

stmt = conn.createStatement();

// Execute Statement to get product Information from
the Database
rset = stmt.executeQuery(" SELECT log_field1 " +
" FROM " + "transaction where log_field5 =
'596612'");

while (rset.next())
System.out.println(rset.getString ("log_field1"));

// Close Result Set and Statement
rset.close();
stmt.close();
}
else{
System.out.println("connection NOT made");
}
}


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/2/2004



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.