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 sub class member using super class objectHow 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 classRandom
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 - StrutsHow 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
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 How to Compress file using Deflater class in javaHow 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 generate pdf file in strutshow 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 strutshow 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 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 FileOutputStreamHow 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 FileWriterHow 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 fileclass file
How to create
class file in jsf easily
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
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>
<
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 fileclass file
how to convert java classfile into java sourcefile
Struts file downloading - StrutsStruts 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 CONCEPTRANDOM
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 Internationalization using struts - StrutsInternationalization
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