A question on Environment Variables and Reading a autoNumber from Database

Hi Everybody,

I need to set two variables as env variables.
viz. DMV_CONNECT which is the connect string to my database.
and DMV_FILE which is a filename.
I would like to know how to set these as env variables, and after having done this, how to read it into my java program.

The other thing is that i need to enter something into a database, which has the first column as an autonumber. The moment i do the insert, i would like to know the value assigned by this autonumber. How do i find this out.?

Thanks in advance.
prbhugra11Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
g_senthilkumarConnect With a Mentor Commented:
HI,
   You can define environment variables and in the java program you can access the value also.
   Do like this:
   First set environment variable
like this
  set DMV_HOME=jdbc:odbc:mysource
   And then in the prorgam you can the value of this environment variable like this
   String dmvhome=System.getProperty("DMV_HOME");
   But when you run the program you have to pass the environment variable to the program using -D option
 java -DDMV_HOME="%DMV_HOME%" GetProperty
  Assume that my program name is GetProperty.java;
 
0
 
vladi21Commented:
1)
Getting System Properties
http://java.sun.com/docs/books/tutorial/applet/practical/properties.html

System.getProperties
public static Properties getProperties()
Determines the current system properties.
If there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.

The current set of system properties is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized.

This set of system properties always includes values for the following keys: Key Description of Associated Value
java.version Java version number
java.vendor Java vendor-specific string
java.vendor.url Java vendor URL
java.home Java installation directory
java.class.version Java class format version number
java.class.path Java class path
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX)
user.name User's account name
user.home User's home directory
user.dir User's current working directory

Exceptions
SecurityException if the current thread cannot access the system properties.

or u can use JNI
http://java.sun.com/docs/books/tutorial/native1.1/index.html
http://www.pbs.mcp.com/ebooks/1575211025/ch30.htm
http://www.sys-con.com/java/iss1/javan.htm
http://bogart.sip.ucm.es/demos/javawn/native.html
http://developer.netscape.com/viewsource/

also u can write a custom java wrapper using JNI_CreateJavaVM.
0
 
vladi21Commented:
2) post ur code
or maybe its Q for DB topic area?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
vladi21Commented:
2)
25. There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

No, but it is easy to find the number of rows. If you are using a scrollable result set, rs, you can call the methods rs.last and then rs.getRow to find out how many rows rs has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT column in the SELECT clause.


also look
http://tactika.com/realhome/javaht/java-d1.html
http://codeguru.developer.com/java/Miscellaneous/Database/index.shtml
http://java.sun.com/docs/books/jdbc/intro.html
http://java.sun.com/products/jdbc/faq.html

0
 
vladi21Commented:
2)
25. There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

No, but it is easy to find the number of rows. If you are using a scrollable result set, rs, you can call the methods rs.last and then rs.getRow to find out how many rows rs has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT column in the SELECT clause.


also look
http://tactika.com/realhome/javaht/java-d1.html
http://codeguru.developer.com/java/Miscellaneous/Database/index.shtml
http://java.sun.com/docs/books/jdbc/intro.html
http://java.sun.com/products/jdbc/faq.html

0
 
Ravindra76Commented:


Create Properties file and add them to propeties file.

and get the property whenever necessary.

Properties class is in java.util. package.

Best of luck
0
 
vishoneCommented:

 Hi prbhugra11,

 For the other question you asked,

 Create a program stored in database, that
      (1) Inserts a row into the table
      with the values passed from the
      java program.
      (2) Returns the number populated
      in the first column.

 For autonumbering, create a trigger on the
 table in which you are inserting such that
 it fires while inseting and populates  the
 first field from a sequence.

 The merit of this approach is that you dont
 have to access database twice - once for
 inserting and second time for checking the
 autonumber generated.

 - Vish

0
 
Ravindra76Commented:
You can define your own properties through Properties() class
0
 
vladi21Commented:
g_senthilkumar - may be better post comments ?

prbhugra11 - waiting for ur comments
0
All Courses

From novice to tech pro — start learning today.