Hi..
i want to use mysql without installing on client system..
So i planned to use mxj.. but this was not helping .. It is trying to access my mysql which i installed.. Can somebody help me..

Iam using mysql-connector-java-5.1.5-bin.jar,aspectjrt.jar,mysql-connector-mxj-gpl-5-0-9.jar,mysql-connector-mxj-gpl-5-0-9-db-files.jar
files..

Process i followed:
1. Set the classpath for all these jar files.
2.I created the data_dir.jar file , which contains the data directory of mysql .. This data_dir should be replaced into the mysql-connector-mxj-gpl-5-0-9-db-files.jar which already contains the data_dir.jar...

Iam using the following code:

package javaapplication;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import com.mysql.management.MysqldResource;
import com.mysql.management.MysqldResourceI;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;


public class ConnectorMXJUrlTestExample {
    public static String DRIVER = "com.mysql.jdbc.Driver";

    public static String JAVA_IO_TMPDIR = "java.io.tmpdir";

    public static void main(String[] args) throws Exception {
        File ourAppDir = new File(System.getProperty(JAVA_IO_TMPDIR));
        File databaseDir = new File(ourAppDir, "mysql-mxj7");
        int port = Integer.parseInt(System.getProperty("c-mxj_test_port",
                "3346"));
        String dbName = "timeandattendancedb";

        String url = "jdbc:mysql:mxj:///" + dbName
                + "?" + "server.basedir=" + databaseDir.getPath() //
                + "&" + "createDatabaseIfNotExist=true"//
                + "&" + "server.initialize-user=true" //
        ;
       System.out.println("dta dir"+databaseDir.getPath());
       String userName = "root";
       String password = "admin";

        MysqldResource mysqldResource = startDatabase(databaseDir, port,
                userName, password);

        String deptName = null;
        Class.forName(DRIVER);
		StringBuffer selectQry=new StringBuffer("select DepartmentName  from Department where DepartmentName=");
		selectQry.append("'");
		selectQry.append("HRM");
		selectQry.append("'");
		Statement stmt = null;
		ResultSet rs = null;        
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, userName, password);
			stmt = conn.createStatement();
		    	rs = stmt.executeQuery(selectQry.toString());
		    	System.out.println("lQuery:"+selectQry.toString());
		    	while(rs.next()){
		    			deptName = rs.getString("DepartmentName");
		    	}
                        System.out.println("dept..:"+deptName);
            System.out.flush();
            Thread.sleep(100); // wait for System.out to finish flush
        } finally {
            try {
                if (conn != null)
                    conn.close();
                if(stmt!=null)
                     conn.close();
                if(rs!=null)
                    rs.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
           try {
                mysqldResource.shutdown();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static MysqldResource startDatabase(File databaseDir, int port,
            String userName, String password) {
        MysqldResource mysqldResource = new MysqldResource(databaseDir);

        Map database_options = new HashMap();
        database_options.put(MysqldResourceI.PORT, Integer.toString(port));
        database_options.put(MysqldResourceI.INITIALIZE_USER, "true");
       database_options.put(MysqldResourceI.INITIALIZE_USER_NAME, userName);
       database_options.put(MysqldResourceI.INITIALIZE_PASSWORD, password);

        mysqldResource.start("test-mysqld-thread", database_options);

        if (!mysqldResource.isRunning()) {
            throw new RuntimeException("MySQL did not start.");
        }

        System.out.println("MySQL is running.");

        return mysqldResource;
    }

}

Error iam getting:

init:
deps-jar:
compile-single:
run-single:
dta dirC:\DOCUME~1\user\LOCALS~1\Temp\mysql-mxj7
[C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj7\bin\mysqld-nt.exe]
[MysqldResource] launching mysqld (test-mysqld-thread)
InnoDB: Error: log file .\ib_logfile0 is of different size 0 25165824 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
090521 12:22:43 [Note] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj7\bin\mysqld-nt.exe: ready for connections.
Version: '5.0.51a-community-nt' socket: '' port: 3346 MySQL Community Edition (GPL)
[MysqldResource] mysqld running as process: 336
MySQL is running.
[MysqldResource] stopping mysqld (process: 336)
090521 12:22:49 [Note] C:\Documents and Settings\narayana\Local Settings\Temp\mysql-mxj7\bin\mysqld-nt.exe: Normal shutdown

090521 12:22:49 [Note] C:\Documents and Settings\narayana\Local Settings\Temp\mysql-mxj7\bin\mysqld-nt.exe: Shutdown complete

[MysqldResource] clearing options
Exception in thread "main" com.mysql.jdbc.CommunicationsException: Communications link failure
[MysqldResource] shutdown complete

Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at javaapplication.ConnectorMXJUrlTestExample.main(ConnectorMXJUrlTestExample.java:50)
Caused by: com.mysql.management.util.SQLRuntimeException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.management.driverlaunched.ServerLauncherSocketFactory.alreadyStarted(ServerLauncherSocketFactory.java:159)
at com.mysql.management.driverlaunched.ServerLauncherSocketFactory.ensureMysqlStarted(ServerLauncherSocketFactory.java:81)
at com.mysql.management.driverlaunched.ServerLauncherSocketFactory.connect(ServerLauncherSocketFactory.java:71)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
... 6 more
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:894)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3808)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1256)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.mysql.management.driverlaunched.ServerLauncherSocketFactory.alreadyStarted(ServerLauncherSocketFactory.java:154)
... 10 more
Java Result: 1
BUILD SUCCESSFUL (total time: 7 seconds)

I think you miss server name (localhost)

Its your code :

 String url = "jdbc:mysql:mxj:///" + dbName                + "?" + "server.basedir=" + databaseDir.getPath() //                + "&" + "createDatabaseIfNotExist=true"//                + "&" + "server.initialize-user=true" //        ;

and Its code at http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html


String url = "jdbc:mysql://localhost:" + port + "/" + dbName //
                    + "?" + "createDatabaseIfNotExist=true"//
            ;

Note:
Read this link http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-options.html

It is about the to setting up Server Options:

If set to true, the default anonymous and root users will be removed and the user/password combination from the connection URL will be used to create a new user. For example:

String url = "jdbc:mysql:mxj://localhost:" + port
        + "/alice_db"
        + "?server.datadir=" + dataDir.getPath()
        + "&server.initialize-user=true"
        + "&createDatabaseIfNotExist=true"
        ;

Thanks for your reply...
I added the server name.. but i am getting different error (its telling incorrect information in file: '.\timeandattendancedb\department.frm')..
Plz help me out..

Code:

String url = "jdbc:mysql:mxj://localhost:" + port
        + "/timeandattendancedb"
        + "?server.datadir=" + databaseDir.getPath()
        + "&server.initialize-user=true"
        + "&createDatabaseIfNotExist=true";

Error:

init:
deps-jar:
compile-single:
run-single:
dta dirC:\DOCUME~1\user\LOCALS~1\Temp\mysql-mxj2
[C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe]
[MysqldResource] launching mysqld (test-mysqld-thread)
InnoDB: Error: log file .\ib_logfile0 is of different size 0 25165824 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
090526 10:03:31 [Note] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe: ready for connections.
Version: '5.0.51a-community-nt' socket: '' port: 3306 MySQL Community Edition (GPL)
[MysqldResource] mysqld running as process: 3364
MySQL is running.
[MysqldResource] stopping mysqld (process: 3364)
090526 10:03:37 [ERROR] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe: Incorrect information in file: '.\timeandattendancedb\department.frm'
090526 10:03:37 [ERROR] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe: Incorrect information in file: '.\timeandattendancedb\department.frm'
090526 10:03:37 [Note] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe: Normal shutdown

090526 10:03:37 [Note] C:\Documents and Settings\user\Local Settings\Temp\mysql-mxj2\bin\mysqld-nt.exe: Shutdown complete

[MysqldResource] clearing options
[MysqldResource] shutdown complete
Exception in thread "main" java.sql.SQLException: Incorrect information in file: '.\timeandattendancedb\department.frm'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2537)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2466)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)

I guess that this problem is due to version conflict or table named department - department.frm is modified externally.

This article has been dead for over six months. Start a new discussion instead.