Good Morning Ryan-
i encounterd a no suitable class situation yesterday and here was my solution
(in minute detail)
public static java.sql.Connection getMySQLConnection() throws
java.lang.Exception
{
StringBuffer dbUrl_buff=new StringBuffer(); //buffer to accumulate
all of the individual parameters
String dbUrl = "jdbc:mysql://";
//jdbc:msql://localhost:3306/comm2ser?user=mgainty&password=StupidAmericanContractor
java.sql.Connection failoverConnection = null;
boolean datadir_boolean=false;
datadir_boolean=(getMysqlVariable("datadir").indexOf('\\') != -1);
//MYSQL needs the datadir otherwise where would the DB data be located
if(datadir==false) System.out.println("MSQYL datadir is null please
specify datadir in %TOMCAT_HOME%/bin/parameters.text");
else
{ // work for this test
dbUrl_buff.append(dbUrl);
java.util.Properties props=new java.util.Properties();
java.util.Properties urlProps = new
com.mysql.jdbc.NonRegisteringDriver().parseURL(dbUrl, null);
//There are 2 ways to feed parameters (URL or properties) because I want to
make sure the connection takes place i will implement both URL and properties
to hold the parameters
//HOST
if(c_sHOST==null)
c_sHOST=urlProps.getProperty(com.mysql.jdbc.Driver.HOST_PROPERTY_KEY);
if(c_sHOST==null) c_sHOST="localhost";
props.setProperty(com.mysql.jdbc.Driver.HOST_PROPERTY_KEY ,
c_sHOST);
System.out.println("MYSQLCONNECTION c_sHOST="+c_sHOST);
dbUrl_buff.append(c_sHOST);
//PORT
if(c_sPORT==0) c_sPORT=new
java.lang.Integer(urlProps.getProperty(com.mysql.jdbc.Driver.PORT_PROPERTY_KEY)).intValue();
if(c_sPORT=3306) c_sPORT=3306;
props.setProperty(com.mysql.jdbc.Driver.PORT_PROPERTY_KEY , new
java.lang.Integer(c_sPORT).toString());
System.out.println("MYSQLCONNECTION c_sPORT="+c_sPORT);
dbUrl_buff.append(":");
dbUrl_buff.append(new java.lang.Integer(c_sPORT).toString());
//DBName
if(c_sDBNAME==null)
c_sDBNAME=urlProps.getProperty(com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY);
if(c_sDBNAME==null) c_sDBNAME="test";
props.setProperty(com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY,c_sDBNAME);
System.out.println("MYSQLCONECTION database="+c_sDBNAME);
dbUrl_buff.append("/");
dbUrl_buff.append(c_sDBNAME);
System.out.println("driverbuff="+dbUrl_buff.toString());
//USER
if(c_sDBUSER==null) c_sDBUSER=
urlProps.getProperty(com.mysql.jdbc.Driver.USER_PROPERTY_KEY);
if(c_sDBUSER==null) c_sDBUSER="root";
props.setProperty(com.mysql.jdbc.Driver.USER_PROPERTY_KEY,c_sDBUSER);
System.out.println("MYSQLCONNECTION c_sDBUSER="+c_sDBUSER);
dbUrl_buff.append("?UID=");
dbUrl_buff.append(c_sDBUSER);
System.out.println("driverbuff="+dbUrl_buff.toString());
//PASSWORD
if(c_sDBPASSWORD==null)
c_sDBPASSWORD=urlProps.getProperty(com.mysql.jdbc.Driver.PASSWORD_PROPERTY_KEY);
props.setProperty(Driver.PASSWORD_PROPERTY_KEY,c_sDBPASSWORD);
System.out.println("MYSQLCONNECTION c_sDBPASSWORD="+c_sDBPASSWORD);
dbUrl_buff.append("&PWD=");
dbUrl_buff.append(c_sDBPASSWORD);
System.out.println("driverbuff="+dbUrl_buff.toString());
//debug
debug = urlProps.getProperty(com.mysql.jdbc.Driver.DEBUG);
System.out.println("MYSQLCONNECTION debug="+debug);
props.setProperty(new
java.lang.Boolean(com.mysql.jdbc.Driver.DEBUG).toString(), new
java.lang.Boolean(debug).toString());
dbUrl_buff.append("&debug=");
dbUrl_buff.append(debug);
System.out.println("driverbuff="+dbUrl_buff.toString());
//trace
System.out.println("MYSQLCONNECTION trace="+trace);
props.setProperty(new
java.lang.Boolean(com.mysql.jdbc.Driver.TRACE).toString(), new
java.lang.Boolean(trace).toString());
dbUrl_buff.append("&trace=");
dbUrl_buff.append(trace);
System.out.println("driverbuff="+dbUrl_buff.toString());
//NUMHOSTS
String numhosts =
urlProps.getProperty(com.mysql.jdbc.Driver.NUM_HOSTS_PROPERTY_KEY);
System.out.println("MYSQLCONNECTION numhosts="+numhosts);
props.setProperty(com.mysql.jdbc.Driver.NUM_HOSTS_PROPERTY_KEY,
"1");
dbUrl_buff.append("&numhosts=");
dbUrl_buff.append(numhosts);
System.out.println("driverbuff="+dbUrl_buff.toString());
//AUTORECONNECT
System.out.println("autoreconnect="+autoreconnect);
props.setProperty("autoreconnect", new
java.lang.Boolean(autoreconnect).toString());
dbUrl_buff.append("&autoreconnect=");
dbUrl_buff.append(autoreconnect);
System.out.println("driverbuff="+dbUrl_buff.toString());
//DRIVER CLASS NAME
props.setProperty("driverClassName",c_sDefaultDriverName);
props.setProperty("autoCommit","true");
props.setProperty("relaxAutoCommit","true");
boolean failOverReadOnly=false;
System.out.println("before props.SetProperty
failOverReadOnly="+failOverReadOnly);
props.setProperty("failOverReadOnly",new
java.lang.Boolean(failOverReadOnly).toString());
//the original design was if the connection fail go to readonly ..not much
point since we need an updateable cursor for insert/update
try
{
System.out.println("before getConnection
dbUrl="+dbUrl_buff.toString());
System.out.println("before getConnection props="+props);
java.lang.Class.forName(c_sDefaultDriverName);
java.sql.DriverManager.registerDriver((com.mysql.jdbc.Driver)java.lang.Class.forName(c_sDefaultDriverName).newInstance());
failoverConnection=java.sql.DriverManager.getConnection(dbUrl_buff.toString(),
props);
failoverConnection.setAutoCommit(true);
}
catch(java.sql.SQLException sql_exception)
{
System.out.println("MYSQL DriverManager.getConnection routine
has produced an error message="+sql_exception);
}
finally
{
//resource cleanup such as closing orphaned connection or
statement handles
}
}
conn=failoverConnection;
System.out.println("getMySQLConnection returns
failoverConnection="+failoverConnection);
return failoverConnection;
}
HTH
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung.
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung
fuer den Inhalt uebernehmen.
> Subject: RE: JDBC error in test when run from Linux
> Date: Sat, 10 Apr 2010 07:16:43 +0000
> From: [email protected]
> To: [email protected]
>
> I was able to test with 2.2.1 and it appears resolved.
>
> -Ryan
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On
> Behalf Of Shelley, Ryan
> Sent: Friday, April 09, 2010 7:37 AM
> To: Maven Users List
> Subject: RE: JDBC error in test when run from Linux
>
> It is a multi-module, but CoreDataSource is not the module being built.
> We have an Ant script that runs the Maven builds for a bunch of
> interconnected modules to test the end-to-end build process for the
> project. CoreDataSource is one of the first modules built. Later,
> another module uses that JAR that is installed in the local repository
> when running its tests. So CoreDataSource isn't even involved in the
> Maven build of the second module other than by being a dependency.
>
> /
> +-pom.xml
> +-CoreDataSource/
> + +-core-datasource/
> + +-pom.xml
> +-OtherModule/
> + +-other-module/
> + +-pom.xml
>
> I dug around more yesterday and came across this JIRA:
>
> http://jira.codehaus.org/browse/MNG-3542
>
> It may be related to my issue, so I'm having the admin update the
> version of maven on the server running Hudson. As Wayne noted in the
> last email, we are running an older Maven that has known issues, so I'll
> reply back when he's done if it's still an issue. Thanks!
>
> -Ryan
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On
> Behalf Of Justin Edelson
> Sent: Friday, April 09, 2010 6:37 AM
> To: Maven Users List
> Subject: Re: JDBC error in test when run from Linux
>
> Can you post the properties file you're referencing as well as the
> resources section of the effective pom? This looks like a resource
> filtering problem to me...
>
> And when you say that "CoreDtaSource/core-datasource" is a separate
> module in "the main build," do you mean that both
> CoreDataSource/core-datasource and your application are both modules in
> a multi-module build? If so, does this error only happen when your
> application build is done within the context of a multi-module build or
> both in multi-module and single-module builds?
>
> i.e.
>
> if your project structure is
> /
> +-pom.xml
> +-CoreDataSource/
> + +-core-datasource/
> + +-pom.xml
> +-app/
> +-pom.xml
>
> do you get the error when running Maven from / and /app/ or just /?
>
> Justin
>
> On 4/8/10 7:04 PM, Shelley, Ryan wrote:
> > We've been building our application on Maven 2.1 for awhile just fine.
> > We build it manually and with a continuous integration tool (Hudson)
> > without issue. I moved Hudson from a Windows box to a Linux box, and
> > suddenly we started getting this following error running the tests:
> >
> >
> >
> > 2010-04-08 15:56:51,846 [main] ERROR
> > org.hibernate.util.JDBCExceptionReporter - Cannot create JDBC driver
> of
> > class 'com.jnetdirect.jsql.JSQLDriver' for connect URL
> > 'http://maven.apache.org/CoreDataSource/core-datasource
> > <http://maven.apache.org/CoreDataSource/core-datasource> ' Cannot
> create
> > JDBC driver of class 'com.jnetdirect.jsql.JSQLDriver' for connect URL
> > 'http://maven.apache.org/CoreDataSource/core-datasource
> > <http://maven.apache.org/CoreDataSource/core-datasource> '
> > java.sql.SQLException: No suitable driver
> >
> >
> >
> > "CoreDataSource/core-datasource" is a separate custom Maven module
> > dependency in the main build. I'm not sure where it's picking up this
> > value instead of using the one we have in our properties file,
> > especially being that this works fine on Windows and Mac OSX. Any
> > ideas?
> >
> >
> >
> > Thanks!
> >
> >
> >
> > -Ryan
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3