Static versus non-Static methods?
Static versus non-Static methods?
- Subject: Static versus non-Static methods?
- From: Jeffrey Pearson <email@hidden>
- Date: Wed, 22 Mar 2006 16:18:48 -0800
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:
This email sent to email@hidden