Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A point of organization advice...



I am building a Swing app that references and updates mySQL on localhost.

It seems to me that I would create the connect.java class in a separate file, outside of main, and have an instance of that class created in main.java. In turn all windows (all of which are in separate classes) would reference the connection object that lives within main.java.

It seems this is the way it should be done, but I'd like to see how the pros suggest. Not sure how clearly this concept needs to be illustrated, but here goes...

// connect.java

import java.sql.*;

public class connect {
	
	public static Connection conn = null;
	
	public connect($driver, $ip, String $db, $user, $pass) {
		
		// start appropriate try & exception catches...
		
		Class.forName($driver).newInstance();

		conn = DriverManager.getConnection("jdbc:mysql://"
		+ $ip
		+ "/"
		+ "$user="
		+ $user
		+"&password="
		+ $pass);

	// end appropriate try & exception catches...

	}
}


// main.java

public class Main {
	
	Connection conn;
	
	public class attemptConnect($driver, $ip, $db, $user, $pass) {
		Connection conn = new connect($driver, $ip, $db, $user, $pass);
	}

	public static void main(String[] args) {
		// initialize and display windows within protected theads.
	}
}

public class myWindow1 {
	//when a button is pushed...
	main.attemptConnect($uiDriver, $uiIP, $uiUser, $uiPass);
	// myWindow1 is hidden
	//myOtherWindow is made visable....
}

public class myOtherWindow {
	main.conn.createStatement().exectueQuery("SELECT * FROM users");
	
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: 10.4.11 Java Hang/Crash (From: Doug Zwick <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.