how to access the messagresource.proprties filevalues in normal class file using struts

how to access the messagresource.proprties filevalues in normal class file using struts

i want to access the below username and password in class file.Plz help to me.


messageresource.properties files
username=system
password=system





My class file is

import java.io.PrintStream;
import java.sql.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.servlet.http.*;

import org.omg.CORBA.Request;
public class ConnectionDb {
public static Connection con=null;

//pradeep reddy



public static Connection getConnectionDb()throws Exception{


try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","system");




System.out.println("Connected database");
}catch(Exception e){
System.out.println("unnable to connect"+e);
}return con;
}
public static void main(String args[])throws Exception{
con=ConnectionDb.getConnectionDb();

System.out.println("connected");
}
}
View Answers

February 11, 2010 at 3:32 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.sql.*;
import java.util.*;
class UsePropertiesFile{
public static void main(String[] args)throws Exception {
Properties prop = new Properties();
prop.load(new FileInputStream("messageresource.properties"));
String user = prop.getProperty("username");
String pass = prop.getProperty("password");

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",user,pass);
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from data");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
}
}

Thanks









Related Tutorials/Questions & Answers:
how to access the messagresource.proprties filevalues in normal class file using struts - Struts
how to access the messagresource.proprties filevalues in normal class file using struts  i want to access the below username and password in class... password=system My class file is import java.io.PrintStream; import
How to access sub class member using super class object
How to access sub class member using super class object  class A{ } class B extends A{ int b=1; } class Test{ public static void main(String args[]) { what to do here to access sub class variable b using super class object
Advertisements
Random Access File class
Random Access File class  Write a short note on Random Access File class.   Please visit the following link: Java Random Access File
How and Where we Access struts Properties file - Struts
How and Where we Access struts Properties file   Hi Friends, am new to struts.I read that " you can store variables in xml file(properties file) and for future enhancements we just call properties file . Now i want to implement
How to Compress file using DeflaterOutputStram class in java.
How to Compress file using DeflaterOutputStram class in java. In this tutorial, we will discuss  how to use DeflaterOutputStream class in java... will compressed the data of a file by using DeflaterOutputStream class
how to forward select query result to jsp page using struts action class
how to forward select query result to jsp page using struts action class  how to forward select query result to jsp page using struts action class
how to store image file and videofile in ms access database using java? - JDBC
how to store image file and videofile in ms access database using java?  how to store image file and video file in ms access database using java
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf using itext?  I am writing a pdf using itext where i add a image... accomplish this.I am using simple java program to write the pdf.Not a servlet.Thanks
How to create a zip file and how to compare zip size with normal text file
How to create a zip file and how to compare zip size with normal text file  Hi, how are you?I hope you are fine.I want program like how to create zip.../ZipCreateExample.shtml but when i verified the size of zip and normal file,normal file is showing
struts url problem in Switching module using SwitchAction class - Struts
struts url problem in Switching module using SwitchAction class  when i use SwitchAction class,it creates a problem take a examle when i go... and by using redirect tag i can not get the ArrayList Object because by using
Decompress file using Inflater class.
Example, we will explain how to decompress file using Inflater class. The Inflater...Decompress file using Inflater class. In this tutorial, we will define the use of Inflater class. The Inflater class provide support for Decompression using
Open a .doc file by click on the link using struts - Struts
Open a .doc file by click on the link using struts   I want to open a doc extension file when i click a link on jsp page .I know only about which is write in web.xml but not exactly know how i do this.Plz any one can help me
How to Compress file using Deflater class in java
How to Compress file using Deflater class in java. In this Example, we will discuss  how to use Deflater class in java. The Deflater class is used to compressed data by using ZLIB library. The Deflater class is available
Understanding Struts Action Class
Understanding Struts Action Class       In this lesson I will show you how to use Struts Action Class and forward a jsp file through it.  What is Action Class?ADS
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both  How to include Two multi rows, one with a file Upload and another with normal fields, have problem while
how to access windows registry information using java?
how to access windows registry information using java?  can any one help me how to access windows registry information using java
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values are stored in database,the database name is registration. In another form i am
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values are stored in database,the database name is registration. In another form i am
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
how to read the .proprties file from struts - Struts
how to read the .proprties file from struts   errpr is :file not found exception:applicationresource.proprties file {system canot find file path"; How to set the file path.  Hi Friend, It seems that you haven't
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
how to develope a struts application using hibernate?
how to develope a struts application using hibernate?  Hi Folks, I am very new to hibernate.I want to develope a login page in struts their username and password should validate against database using hibernate framework
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use
How to write to file using FileWriter
How to write to file using FileWriter  hi, How to write to file using FileWriter thanks,   Hi, To writing in a file in Java program we... of the FileWriter class can be created using the following of its constructor i.e. FileWriter
How to access session value using OGNL.
How to access session value using OGNL. In this example, you will see how to access value of session using OGNL expression language in struts2.  1-index.jsp <html>ADS_TO_REPLACE_1 <head> <title>Access
class file
class file  How to create class file in jsf easily
How to Open Picture From M.S. Access Database using Java Servlet ?
How to Open Picture From M.S. Access Database using Java Servlet ?  Hi all my Friends I have below code which insert a picture into M.S. Access Database But i m still not able to open this picture through Java using M.S. Access
How to make a chat application using Struts 2 ?
How to make a chat application using Struts 2 ?  Hello, I'm working on my final year project. i've to add chat application in that. how it can be done? 'm using eclipse for that.... plzzz reply
how to connect java with ms access using odbc in eclipse
how to connect java with ms access using odbc in eclipse  import java.sql.*; class AccessDatabase{ public static void main(String[] args... Access Driver (*.accdb)};DBQ=student.accdb","",""); Connection con
how to access the object of one frame on clicking a button without using this keyword
how to access the object of one frame on clicking a button without using this keyword  import java.awt.*; import java.awt.event.*; class Mybuttons1...) { System.exit(0); } }); } } class Myclass extends Frame implements
How to zip a file using javascrip?
How to zip a file using javascrip?  hi.. can anyone tell me How to zip a file using javascrip
Using a Random Access File in Java
the characters from a file using the readByte( ) method... RandAccessFile Enter File name : Filterfile.txt Write...;= in.readLine();   File file = new File(str
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp... file upload form to the user</TITLE></HEAD> <
Line by Line reading from a file using Scanner Class
In this section, you will get to know about reading line by line a text file using java.util.Scanner class
why it is very slow when I am using the backend as microsoft access file for running the java webapplication - SQL
why it is very slow when I am using the backend as microsoft access file for running the java webapplication  I am using the backend as microsoft access file for running the java webapplication.it is very slow when twoor mor
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want... this ... i m able to access a Ms-access via JDBC but cant find the file wen
class file
class file  how to convert java classfile into java sourcefile
Struts file downloading - Struts
Struts file downloading  how to download a file when i open a file from popup option like save ,open and cancel file is opened but file content is not showed even i check the file size also and generating excetion like
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program that stores the names... in an alphabetical order in a file and display it back on console. Do not use the RandomAccessFile class
Random Access File.
Random Access File.  Explain Random Access File
Internationalization using struts - Struts
Internationalization using struts   Hi, I want to develop a web application in Hindi language using Struts. I have an small idea... to convert hindi characters into suitable types for struts. I struck here please
How to access Contacts from gmail using LDAP in JSP dropdown list
How to access Contacts from gmail using LDAP in JSP dropdown list  HI, I am creating a JSP page in which i have to make a dropdown box, and access gmail contacts in that drop downlist using LDAP. Can any one plz help me out
File Upload in Struts.
File Upload in Struts.  How to do File Upload in Struts
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... using this jsp,but i want to CollegeAction class and CollegeForm class how to do...="file" name="file[]" multiple/> <html:submit value = "S U B M I T"/>

Ads