The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

XXX

Posted by XXX on May 26, 2001 at 9:59 AM

Using MySQL as a JDBC database on Linux
Set up your environment to access the MySQL adapter classes
Assuming that YOU ARE RUNNING A C SHELL,

The following command must be typed in each terminal you wish to access your database from.

This next command configures how to access the MySQL JDBC driver

setenv CLASSPATH .:/usr/local/share/app/MySQL/mm.mysql.jdbc-1.2c

The next command provides a short-cut, just type the command mysqli, to look at any information in the database, such as tables etc, from the command-line.

alias mysqli �mysql �h mysql �p�

Setting up your environment via the .cshrc file
Alternatively you can add this command to your .cshrc file and the configuration will be automatically invoked when each terminal is started. To do this add the following lines to your .cshrc file and save. This configuration information will then be read by any new terminal windows that you start.

N.B. make sure there is a return after each line including the last line and check for typing mistakes before saving)

setenv CLASSPATH .:/usr/local/share/app/MySQL/mm.mysql.jdbc-1.2c

alias mysqli �mysql �h mysql �p�

Modify your JDBC application to access this data source
For example, see this MySQL JDBC sample. Ask your tutor for a username and password

Modify this sample to use your username and password.

Compile and execute the database application
Compile the example 'javac TestMySQLJDBC.java'

If you say any compilation errors here such as driver errors, it probably means your classpath is wrong.

Run it 'java TestMySQLJDBC' to create the empty database table COFFFE2 in the database (called your username) with several columns but no actual rows.

N.B. the MySQL database server is running on PC2, log on any other Linux box other than PC2 to run your database application.

Use MySQL in interactive mode to view your database tables
In interactive mode you give commands to view the database tables and issue SQL commands such as select.

N.B. the �;� is very important in interactive mode to complete the command.

If you forget it, you will see a �->�prompt. Type �;� on a line by itself to terminate the command for typing a new one.

Here is a sample interactive session.

Further information about the interactive session commands are found here

.

Further work
Use the other JDBC applications available in the JDBC Java tutorial trail to populate and query your database table.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us