Setting Up MySQL
Posted by: J Aspin
Date: January 06, 2005 01:52PM

Hi All,

I hope somebody can help. I just installed SuSE 9.0 and used Yast to install MySQL. This may sound silly but I am very green when it comes to MySQL and am learning JDBC at college. I am trying to establish a connection to a database in a file. I have set the classpath to point to the mysql.jar file and compiled my program as below:



public class ConnectMS
{
    public static void main(String[] args)
    {

	int i;
	Connection conn = null;

	// loading jdbc-odbc driver
	try{
	    Class.forName("com.mysql.jdbc.Driver").newInstance();
	} catch(Exception e) {
	    System.out.println(e);
	}




	// connecting to database

	try{
	    conn = DriverManager.getConnection
("jdbc:mysql://localhost/music?user=demos&password=demo-pass");
	}


       catch(SQLException se) {
	    System.out.println(se);
	}


	System.out.println("connection is successful!!!");



// Create select statement and execute it

	try{
	    String selectSQL = "select * from films where year = 1987";
	    Statement stmt = conn.createStatement();
	    ResultSet rs1 = stmt.executeQuery(selectSQL);


// Retrieve the results

	    while(rs1.next()){
		System.out.println("ID: "+ rs1.getInt(1) + "   TITLE: " + rs1.getString(2) + "   YEAR: " + rs1.getInt(3) + "   DIRECTOR: " +  rs1.getString(4) + "   STARS: " + rs1.getString(5) + "   REVIEW: " + rs1.getString(6));
	   }

	    stmt.close();
	} catch(SQLException se) {
	    System.out.println(se);
	}
    }


}

However, I keep getting an error that states Can't connect to server through socket var/lib/mysql/mysql.

The following is the status of my set up presently. I'm afraid that I am unsure whether or not I need to set up mysql to manage multiple servers or not. In which case do I need to change to TCP/IP ports..? Please advise I am running out of time for my project deadline:

Current Configuration:

Connection id: 1
Current database: mysql
Current user: root@localhost
SSL: not in use
Current pager: less
Using outfile: ' '
Server version: 4.0.21
Protocol version: 10
Connection: Localhost via UNIX socket
Client characterset: latin1
Server characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 19 sec.

END CONFIGURATION

Thanks Guys I could really use the help. I know nothing about mysql.

Cheers from U.K.
Jaspin

Options: ReplyQuote


Subject
Written By
Posted
Setting Up MySQL
January 06, 2005 01:52PM
January 06, 2005 02:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.