• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Static versus non-Static methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static versus non-Static methods?


  • Subject: Re: Static versus non-Static methods?
  • From: Jeffrey Pearson <email@hidden>
  • Date: Wed, 22 Mar 2006 17:50:47 -0800

Robert,

I forgot to include the parent package in the page which is why I was getting the error(OK. I got spoiled. IntelliJ automatically adds it). But I did still need to add the new to the line. Thanks.


Jeff

On Mar 22, 2006, at 4:32 PM, Robert Walker wrote:

Registry registry = Registry();

I think you want: Registry registry = new Registry();

Then your methods don't have to be static because you will be sending messages to a new instance of a Registry object?
--
Robert Walker
email@hidden


There are 10 types of people in the world, those who count in binary, and those who don't.


On Mar 22, 2006, at 7:18 PM, Jeffrey Pearson wrote:

More of a Java question than strictly WebObjects but this exact same code works in the jp/servlet web app.

When I compile, I get:

cannot resolve symbol on line:

Registry registry = Registry();

in the Main.java file.

If I remove the static parameter from the getMySQLConnection line, I get:

com/metrohero/web/PublisherFunctions.java:22: non-static method getMySQLConnection() cannot be referenced from a static context




********************************************************************* **
//
// Main.java: Class file for WO Component 'Main'
// Project metropolisadmin
//
// Created by jeffreypearson on 3/21/06
//


import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
import com.metrohero.common.*;

public class Main extends WOComponent {
    public String userName;
    public String password;
	public Main(WOContext context) {
        super(context);
    }

public WOComponent validateLogin() {
if ("".equalsIgnoreCase(userName) || "".equalsIgnoreCase (password)) {
return pageWithName("Main");
}
try {
Registry registry = Registry();
Connection MySQLConnection = registry.getMySQLConnection();
Statement stmt = MySQLConnection.createStatement();
ResultSet rset = stmt.executeQuery("SELECT userid from users where username = '" + userName + "' AND password = '" + password + "'");
if (rset != null) {
return pageWithName("Home");
} else {
return pageWithName("Main");
}
} catch (SQLException SQLEx) {
System.out.println("SQL Exception:" + SQLEx);
}


        //return pageWithName("Home");
    }

}
*********************************************************

package com.metrohero.common;

//import java.sql.DriverManager;
import java.sql.*;

//import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Driver;




public class Registry {

    //private static OracleDataSource ds;

public static Connection getMySQLConnection() {
Connection MySQLConnection = null;
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
MySQLConnection = DriverManager.getConnection ("jdbc:mysql://64.81.81.18/metropolis? user=username&password=password");
} catch (Exception ex) {
// handle the error
}
return MySQLConnection;
}


    public static void closeMySQLConnection(Connection m_conn)
    {
        try {
            if (m_conn != null) {
                m_conn.close();
            }
        }
        catch (SQLException e) {
            System.out.println("ERROR_OCCURRED");
            e.printStackTrace();
        }
    }
}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Static versus non-Static methods?
      • From: Chuck Hill <email@hidden>
References: 
 >Static versus non-Static methods? (From: Jeffrey Pearson <email@hidden>)
 >Re: Static versus non-Static methods? (From: Robert Walker <email@hidden>)

  • Prev by Date: Re: Application URL
  • Next by Date: Re: Static versus non-Static methods?
  • Previous by thread: Re: Static versus non-Static methods?
  • Next by thread: Re: Static versus non-Static methods?
  • Index(es):
    • Date
    • Thread