Re: R: App + ConnectorJ + MXJ deployment
Eric Herman <[email protected]>
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <1159185786.6244.15.camel@localhost> |
Hi Roberto,
At first glance, the only serious issue I see is that it looks like the
port was forgotten in the JDBC URL connection string:
> dbConn = DriverManager.getConnection("jdbc:mysql://localhost/" +
> DATABASE + "?user=" + USERID + "&password=" + PASSWORD);
That should really look more like:
"jdbc:mysql://localhost" + port + "/" + ...
On Fri, 2006-09-22 at 13:11 +0200, tech wrote:
> Hi Eric,
>
> I sum up the situation.
> Now on the deployment pc I have:
>
> 1) mysql-connector-java-5.0.3-bin.jar in the $JAVA_HOME/jre/lib/ext
> directory
>
> 2) MySQLTest.jar (my Java application)
>
> 3) connector-mxj.jar (my own connector-mxj.jar with the pre-configured DB
> for the above application, created following paragraph 27.4.5.1 and 27.4.5.2
> of the online manual)
>
> 4) aspectjrt.jar (copied and pasted from my development pc).
>
> All of the paths to the above four jar files are in the CLASSPATH of the
> deployment pc.
>
> Attached you can find:
> 1) my Console output. JRE cannot find '5-0-22/Win-x86/mysqld-nt.exe'.
> Actually mysqld-nt.exe is in connector-mxj.jar. I unpacked connector-mxj.jar
> and found it at 5-0-22/Win-x86/.
> 2) my Java class which manages the connection to MySQL.
>
> Thanks for any hint.
The output "java.util.MissingResourceException: Resource
'5-0-22/Win-x86/mysqld-nt.exe' not found" suggests to me that perhaps
there was a problem with the repackaging of the jar. I come to this
guess because from the source we can see the same class loader which
loaded the "Streams" class is responsible for finding the
"5-0-22/Win-x86/mysqld-nt.exe" resource:
public InputStream getResourceAsStream(String name) {
ClassLoader classLoader = getClass().getClassLoader();
return getResourceAsStream(classLoader, name);
}
public InputStream getResourceAsStream(ClassLoader classLoader,
String name) {
InputStream is = classLoader.getResourceAsStream(name);
if (is == null) {
String msg = "Resource '" + name + "' not found";
throw new MissingResourceException(msg, null, name);
}
return is;
}
Therefore it seems that Java was able to load the "Streams" class from
the connector-mxj.jar file, but not able to find the mysqld resource.
Attached, you'll find the console output of my experiment with the java
file you provided. The primary difference is that I am using the
standards "blank" database, not your re-packaged database, so I had to
change the user, password, and database information. Also, I added a
"main" method.
Cheers,
-Eric
>
> Roberto
>
>
>
>
> -----Messaggio originale-----
> Da: Eric Herman [mailto:[email protected]]
> Inviato: giovedì 21 settembre 2006 15.15
> A: tech
> Cc: [email protected]
> Oggetto: Re: App + ConnectorJ + MXJ deployment
>
> Hello Roberto
>
> On Thu, 2006-09-21 at 14:29 +0200, tech wrote:
> > Hi Eric,
> >
> >
> >
> > Now on the deployment pc I have:
> >
> >
> >
> > 1) mysql-connector-java-5.0.3-bin.jar in the $JAVA_HOME/jre/lib/ext
> > directory
> >
> >
> >
> > 2) MySQLTest.jar (my Java application)
> >
> >
> >
> > 3) connector-mxj.jar (my own connector-mxj.jar with the pre-configured
> > DB for the above application, created following paragraph 27.4.5.1 and
> > 27.4.5.2 of the online manual)
> >
> >
> >
> > 4) aspectjrt.jar (copied and pasted from my development pc).
> >
> >
> >
> > All of the paths to the above four jar files are in the CLASSPATH of
> > the deployment pc.
>
> Okay, so far that sounds good.
> >
> >
> >
> > I tried to launch my Java app, but I get the attached Console output.
> >
>
> Just looking at the console output, it looks like perhaps the
> application is trying to make a connection to the database prior to
> calling "start" upon the MysqldResource.
>
> I come to this guess because I do not see any output from Connector/MXJ,
> and I see the exception is "java.net.SocketException:
> java.net.ConnectException: Connection refused: connect" which may
> indicate that the database is not yet started.
>
> > Should I maybe first extract directories and files from
> > connector-mxj.jar and run something ?
>
> Provided you re-packaged the connector-mxj.jar correctly, you shouldn't
> need to extract anything by hand.
>
> If I recall, you had good luck with the ConnectorMXJObjectTestExample
> when doing testing. And I assume that your application's use of
> Connector/MXJ is based upon the ConnectorMXJObjectTestExample, yes?
>
> Do you have some code in your application that looks something like
> this?
>
> /* start mysql */
> MysqldResource mysqldResource = new MysqldResource(databaseDir);
> Map database_options = new HashMap();
> database_options.put("port", Integer.toString(port));
> mysqldResource.start("mysqld-thread", database_options);
>
> /* ... */
>
> String url = "jdbc:mysql://localhost:" + port + "/" + dbName;
> Connection conn = DriverManager.getConnection(url, user, password);
>
> /* ... */
>
> mysqldResource.shutdown();
>
>
> Since I can not see your application it is hard to guess. But, please
> take another look at ConnectorMXJObjectTestExample.java and compare your
> application to the example. Perhaps you will detect a small over-sight.
>
> Cheers
> -Eric
>
>
> >
> >
> > Thanks for your help.
> >
> >
> >
> > Roberto
> >
> >
> >
> >
> >
> >
> --
> Eric Herman, Software Developer
> MySQL AB, www.mysql.com
> VoIP Ext: 6594 US: +1 408 213 6540 Europe: +46 18 174 400
> Mobile: +31 [0]6-20719662
> Are you MySQL certified? www.mysql.com/certification
>
>
--
Eric Herman, Software Developer
MySQL AB, www.mysql.com
VoIP Ext: 6594 US: +1 408 213 6540 Europe: +46 18 174 400
Mobile: +31 [0]6-20719662
Are you MySQL certified? www.mysql.com/certification
--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/[email protected]
AmministrazioneDb_console_out.txt
(text/plain, 2.4 KB)
C:\src\java>SET CLASSPATH CLASSPATH=C:\apps\mysql-connector-java-5.0.3\mysql-connector-java-5.0.3-bin.jar; C:\apps\connector-mxj\connector-mxj.jar;C:\apps\connector-mxj\lib\aspectjrt.jar; C:\src\java C:\src\java>javac packageAntiriciclaggio/*.java Note: packageAntiriciclaggio/AmministrazioneDB.java uses unchecked or unsafe ope rations. Note: Recompile with -Xlint:unchecked for details. C:\src\java>java packageAntiriciclaggio.AmministrazioneDB [MysqldResource] launching mysqld (getOptions) [C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql-mxj\bin\mysqld -nt.exe][--no-defaults][--console][--pid-file=C:\Documents and Settings\user\Loc al Settings\Temp\roberto\mysql-mxj\data\MysqldResource.pid][--socket=mysql.sock] [--datadir=C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql-mxj\ data][--basedir=C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql -mxj][--port=3336] [MysqldResource] launching mysqld (mysql-thread) 060925 4:40:06 InnoDB: Started; log sequence number 0 43655 060925 4:40:06 [Note] C:\Documents and Settings\user\Local Settings\Temp\robert o\mysql-mxj\bin\mysqld-nt.exe: ready for connections. Version: '5.0.22-community-nt' socket: '' port: 3336 MySQL Community Edition (GPL) [MysqldResource] mysqld running as process: 1944 [MysqldResource] stopping mysqld (process: 1944) [MysqldResource] clearing options [MysqldResource] shutdown complete C:\src\java>java packageAntiriciclaggio.AmministrazioneDB [MysqldResource] launching mysqld (getOptions) [C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql-mxj\bin\mysqld -nt.exe][--no-defaults][--console][--pid-file=C:\Documents and Settings\user\Loc al Settings\Temp\roberto\mysql-mxj\data\MysqldResource.pid][--socket=mysql.sock] [--datadir=C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql-mxj\ data][--basedir=C:\Documents and Settings\user\Local Settings\Temp\roberto\mysql -mxj][--port=3336] [MysqldResource] launching mysqld (mysql-thread) 060925 4:40:38 InnoDB: Started; log sequence number 0 43655 060925 4:40:38 [Note] C:\Documents and Settings\user\Local Settings\Temp\robert o\mysql-mxj\bin\mysqld-nt.exe: ready for connections. Version: '5.0.22-community-nt' socket: '' port: 3336 MySQL Community Edition (GPL) [MysqldResource] mysqld running as process: 3620 [MysqldResource] stopping mysqld (process: 3620) [MysqldResource] clearing options [MysqldResource] shutdown complete C:\src\java>
AmministrazioneDB.java
(text/x-java, 2.9 KB)
package packageAntiriciclaggio;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import javax.swing.JOptionPane;
import com.mysql.management.MysqldResource;
public class AmministrazioneDB
{
public static String JAVA_IO_TMPDIR = "java.io.tmpdir";
public static String DRIVER = "com.mysql.jdbc.Driver";
//private static final String DATABASE = "rua142"; // nome del DB
//private static final String USERID = "utente142";
private static final String PASSWORD = "pulsar";
private static final String DATABASE = "test"; // nome del DB
private static final String USERID = "root";
private Connection dbConn = null;
// private File ourAppDir = new File(System.getProperty(JAVA_IO_TMPDIR));
private File ourAppDir = new File(System.getProperty(JAVA_IO_TMPDIR), "roberto");
private File databaseDir = new File(ourAppDir, "mysql-mxj");
private MysqldResource mysqldResource = null;
private int port = 3336;
public AmministrazioneDB()
{
registraDriver();
apriConnessione();
}
private void registraDriver()
{
try {
Class.forName(DRIVER).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} // package-qualified name of the JDBC driver class
}
/** A database connection is established. The forName() method registers the native JDBC driver. Use this
* technique when you want the driver class to be located at runtime instead of at compile time. */
private void apriConnessione()
{
try
{
mysqldResource = new MysqldResource(databaseDir);
Map database_options = new HashMap();
database_options.put("port", Integer.toString(port));
mysqldResource.start("mysql-thread", database_options);
/** The getConnection() method establishes a connection with the MySQL database. The URL required to locate the DB
* access protocol is jdbc:mysql */
//dbConn = DriverManager.getConnection("jdbc:mysql://localhost:"+port+"/" + DATABASE + "?user=" + USERID + "&password=" + PASSWORD);
dbConn = DriverManager.getConnection("jdbc:mysql://localhost:"+port+"/" + DATABASE + "?user=" + USERID);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, "Failed connection to the database");
e.printStackTrace();
}
catch(Exception e)
{ e.printStackTrace(); } // fine blocco try-catch
}
public Connection getConnessione()
{
return dbConn;
}
/** Close database connection */
public void chiudiConnessione() throws SQLException
{
try {
if(dbConn != null) {
dbConn.close(); // Close database connection
}
} finally {
mysqldResource.shutdown();
}
}
public static void main(String[] args) throws Exception
{
AmministrazioneDB amministrazioneDB = null;
try {
amministrazioneDB = new AmministrazioneDB();
} finally {
if (amministrazioneDB != null) {
amministrazioneDB.chiudiConnessione();
}
}
}
} // end class