Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

4409723

Suspended
Original poster
Jun 22, 2001
2,221
0
Hello all!

I'm back for my monthly tech question. For my IB diploma I have use a computer to make a product/item/game to help the local community. I could make a brochure and get 33/35, or If I try to use something more difficult I can go for the 35/35.

My plan is to make a simple game for lower school children to increase their vocabulary. There will be a central server with the MySQL database (with the words/accounts/scores for each kid) and PHP and each client will have a compiled Java client which will interface with the server. This is still in the planning stage and I have until the Autumn to complete it.

Now I'm trying to install MySQL/PHP on my computer to play with. I have installed MySQL and I can connect and create databases. I have also got PHP up and running and I can run the <? PHP PHPInfo ()> test script and that works. How can I get them interfacing? Attached is the diagram I made to explain the idea.

EDIT: In case there are any path sensitive commands I installed both programs in their default locations.

EDIT 2: According to this page I may not even need PHP: http://www.javacoding.net/articles/technical/java-mysql.html
 

Attachments

  • game.jpg
    game.jpg
    86.6 KB · Views: 99
Wes said:
Well I'm glad to see you're all interested! Anyway here is the update:

I'm try to use this: http://www.javacoding.net/articles/technical/java-mysql.html

And I'm fine until I have to set the Classpath, help?
There's a simple way to do this:
Find the location of that .jar file that contains the JDBC driver.
Open Terminal and type "export CLASSPATH=", then drag the .jar file to the terminal to append its path to what you are currently typing.
Once that's done, finish the command by typing ":$CLASSPATH" and pressing return. The typing is without the quotes. Once that's done, you'll need to copy that command you just typed and add that line to your .profile file. The easiest way I know of to do this is to type this command while at the terminal: "cp .profile profile.txt" (without the quotes). Open the profile.txt file in TextEdit and paste the line you copied from the Terminal, then save and close the file. If you got an error message after the cp command saying that the file doesn't exist, ignore it and open TextEdit anyway. Make this new file plain text if it isn't already, then paste that line you copied into the file. Save it as profile.txt in your home directory (not in any subfolders). Once you have a profile.txt file with the new line in it, go back to Terminal and type this command: "cp profile.txt .profile" (without the quotes). Once that's done, close the Terminal (and re-open it if you need to use it some more) and delete that profile.txt file, since it isn't needed any more.
 
wrldwzrd89 said:
There's a simple way to do this:
Find the location of that .jar file that contains the JDBC driver.
Open Terminal and type "export CLASSPATH=", then drag the .jar file to the terminal to append its path to what you are currently typing.
Once that's done, finish the command by typing ":$CLASSPATH" and pressing return. The typing is without the quotes.

Tried it with and without the space but I'm getting an error :(

[127:~] wlb% export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar :$CLASSPATH
tcsh: CLASSPATH: Undefined variable.
[127:~] wlb% export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar:$CLASSPATH
tcsh: CLASSPATH: Undefined variable.
[127:~] wlb%
 
Wes said:
Tried it with and without the space but I'm getting an error :(

[127:~] wlb% export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar :$CLASSPATH
tcsh: CLASSPATH: Undefined variable.
[127:~] wlb% export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar:$CLASSPATH
tcsh: CLASSPATH: Undefined variable.
[127:~] wlb%
Hmm - CLASSPATH doesn't appear to exist. In that case, omit the ":$CLASSPATH" at the end - it isn't needed if CLASSPATH isn't already defined.
EDIT: I forgot to mention - that command is for BASH, not for TCSH. Switch to BASH first by typing "bash" at a tcsh prompt before typing the command.
 
Not working, here is exactly what I'm doing:
Code:
Open terminal
bash [enter]
wlb$ export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar 
[enter]
Go to home directory, no profile
Back to terminal:
cp .profile profile.txt 
Response:cp: .profile: No such file or directory
Go to text edit paste:
export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar 
Make plain text, save in home folder.
Open terminal:
cp .profile profile.txt 
[enter]
No such file or directory
[Mac out window and 5 floors below]

Am I supposed to do something with this file? I have Eclipse if it is easier to set it up in there.
 
I have tried everything and in Eclipse and in JJEdit (Simple compiling program) the only out put I get is: "usage: java TestMySQL host database
"

Edit: I'm beginning to think it has something to do with user/passwords maybe?
Code:
/* import needed for JDBC access */
import java.sql.*;


/**
 *  MySQL Demo Program
 *		this program is just a little demonstration of the usage
 *		of MySQL in combination with Java JDBC
 *
 *  [url]http://www.javacoding.net[/url]
 */
public class TestMySQL {
	
    public void test ( String host, String database ) throws Exception {
	host = "localhost" ;
	database = "test" ;
	  /* first, we'll test whether the MySQL driver is installed */
	  testDriver ( );

	  /* then, we'll get a connection to the database */
      Connection con = getConnection ( host, database );
      
	  /* we create a table */
	  executeUpdate ( con, "create table test (id int not null,text varchar(20))" );
	  
	  /* we insert some data */
	  executeUpdate(con,"insert into test (id,text) values (1,'first entry')");
	  executeUpdate(con,"insert into test (id,text) values (2,'second entry')");
	  executeUpdate(con,"insert into test (id,text) values (3,'third entry')");

	  /* then we'll fetch this data */
	  executeQuery ( con, "select * from test" );

	  /* and we'll destroy the table ... */
      executeUpdate ( con, "drop table test" );
      
	  /* finally, we close the database */
      con.close ( );
    }
    
	
	/**
	 *  Checks whether the MySQL JDBC Driver is installed
	 */	
	protected void testDriver ( ) throws Exception {
    
		try {
			Class.forName ( "org.gjt.mm.mysql.Driver" );
			System.out.println ( "MySQL Driver Found" );
		} catch ( java.lang.ClassNotFoundException e ) {
			System.out.println("MySQL JDBC Driver not found ... ");
			throw ( e );
		}
	}


	/**
	 *  Returns a connection to the MySQL database
	 *
	 */
	protected Connection getConnection ( String host, String database )
          throws Exception {
    
    	String url = "";
	    try {
	    	url = "jdbc:mysql://" + host + "/" + database;
      		Connection con = DriverManager.getConnection(url);
		System.out.println("Connection established to " + url + "...");
		    
		return con;
    	} catch ( java.sql.SQLException e ) {
		System.out.println("Connection couldn't be established to " + url);
		throw ( e );
    	}
	}



    /**
     *  This method executes an update statement
     *  @param con database connection
     *  @param sqlStatement SQL DDL or DML statement to execute
     */
	protected void executeUpdate ( Connection con, String sqlStatement )
          throws Exception {    
    
		try {
			Statement s = con.createStatement ( );
			s.execute ( sqlStatement );      		
			s.close ( );
		} catch ( SQLException e ) {
			System.out.println ( "Error executing sql statement" );
			throw ( e );
		}
	}



    /**
     *  This method executes a select statement and displays the result
     *  @param con database connection
     *  @param sqlStatement SQL SELECT statement to execute
     */
	protected void executeQuery( Connection con, String sqlStatement )
          throws Exception {    
    
		try {
			Statement s = con.createStatement ( );
			ResultSet rs = s.executeQuery( sqlStatement );
    
			while ( rs.next ( ) ) {
				String id = ( rs.getObject ("id").toString() );
				String text = ( rs.getObject ("text").toString() );
				
				System.out.println ( "found record : " + id + " " + text );
			}
			
			rs.close ( );

		} catch ( SQLException e ) {
			System.out.println ( "Error executing sql statement" );
			throw ( e );
		}
    }
    


	/**
	 *  This one is used to start the program.
	 */
	public static void main ( String args[] ) throws Exception {
		if ( args.length == 2 ) {
  		  new TestMySQL ( ).test ( args[0], args[1] );
		} else {
		  System.out.println ( "usage: java TestMySQL host database" );
		}
	}
  	  
  
}
 
Wes said:
Not working, here is exactly what I'm doing:
Code:
Open terminal
bash [enter]
wlb$ export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar 
[enter]
Go to home directory, no profile
Back to terminal:
cp .profile profile.txt 
Response:cp: .profile: No such file or directory
Go to text edit paste:
export CLASSPATH=/Users/wlb/mysql-connector-java-3.0.14-production/mysql-connector-java-3.0.14-production-bin.jar 
Make plain text, save in home folder.
Open terminal:
cp .profile profile.txt 
[enter]
No such file or directory
[Mac out window and 5 floors below]

Am I supposed to do something with this file? I have Eclipse if it is easier to set it up in there.
You had the last command reversed. It should be "cp profile.txt .profile" not "cp .profile profile.txt". That's why you're getting an error message.
 
Done and no errors, but I'm still getting the same output. Driving me crazy.

EDIT: Problem solved. Thanks all those involved!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.