File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Accessing variable from another method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing variable from another method" Watch "Accessing variable from another method" New topic

Accessing variable from another method

Rebecca Witmer
Ranch Hand

Joined: Sep 10, 2004
Posts: 46
I have the following code. On line 38 in method MakeConnection() I am trying to access some variable from method ReadIni()above but it tells me each one "is not accessible or is not a field". What does it want from me?

import java.sql.*;
import java.util.Properties;

class ConnectionMaker {
String database;
String user;
String password;

public void ReadIni() throws IOException{
File iniFile = new File("C:\\Documents and Settings\\rwitmer.NA\\Desktop\\eclipse\\workspace2\\Tree\\config.ini");
FileInputStream fis = new FileInputStream(iniFile);
Properties properties = new Properties();
database = properties.getProperty("database");
user = properties.getProperty("user");
password = properties.getProperty("password");

public ResultSet MakeConnection(String query) {
try {
} catch (IOException e) {
// TODO Auto-generated catch block
ResultSet rs = null;
try {
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());

try {
Statement stmt = null;
rs = null;
Connection conn = DriverManager.getConnection("jdbc:mysql:" + ReadIni().database + "?user=" + ReadIni().user + "&password" + ReadIni().password);

stmt = conn.createStatement();
rs = stmt.executeQuery(query);

} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
return rs;


SCJP 1.4
ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 130
instead of using ReadIni().database, just use database and you should be okay,
remmember you cannot access a method with out a object unless method is static


I agree. Here's the link:
subject: Accessing variable from another method
Similar Threads
unexpected output
How can I put the image into the DataBase?
jsf and database connection problem
errors uploading an image to the database
Reading usersnames/passwords from file for database access