From: Date: June 18 2009 5:23pm Subject: Re: solving paths on the jdbc archive (SOLVED) List-Archive: http://lists.mysql.com/java/9253 Message-Id: <209054.1842.qm@web33001.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable The classpath must be also declared in the manifest, otherwise Class.forNam= e() is unable to find complete path for the class=0AWorks fine now=0A=0A---= On Thu, 6/18/09, Federico Alcantara wrote:= =0A=0A> From: Federico Alcantara =0A> Subject= : Re: solving paths on the jdbc archive=0A> To: "Michel Maria-Sube" =0A> Date: Thursday, June 18, 2009, 2:07 AM=0A> Michel,=0A> can y= ou post the file structure?=0A> Anyway, you can=A0 have the mysql connector= jar in the=0A> same directory as your jar. In such way your classpath=0A> = prefix will be simple ./=0A> For example:=0A> =0A> =A0=A0=A0 yourarchive.ja= r=0A> =A0 =A0 =A0 =A0=0A> mysql-connector-java-5.1.6-bin.jar=0A> =0A> To ru= n your application (assuming Main.java is your=0A> application launcher cla= ss)=0A> =A0=A0=A0 java -cp=0A> ./;./mysql-connector-java-5.1.6-bin -jar you= rarchive.jar=0A> Main=0A> =0A> Normally additional jars are put in a lib su= bdirectory, for=0A> example the folder structure can be as follow:=0A> =A0 = =A0=A0=A0+ yourarchive.jar=0A> =A0 =A0=A0=A0|=0A> =A0 =A0=A0=A0---- lib=0A>= =A0 =A0 =A0 =A0 =A0 |=0A> =A0 =A0 =A0 =A0 =A0 +=0A> mysql-connector-java-5= .1.6-bin.jar=0A> Now your classpath will be prefixed with ./lib/=0A> =A0=A0= =A0 java -cp=0A> ./;./lib/mysql-connector-java-5.1.6-bin -jar yourarchive.j= ar=0A> Main=0A> =0A> You can set your classpath with the values previously = shown=0A> in the -cp option.=0A> =0A> You must make sure that:=0A> 1) The j= ar are EXACTLY located in the directory that you=0A> are specified in the c= lasspath, they are CASE sensitive.=0A> 2) That you have at least read/execu= te access to those=0A> directories.=0A> =0A> Hope this helps!=0A> =0A> =0A>= On Jun 16, 2009, at 6:15 PM, Michel Maria-Sube wrote:=0A> =0A> > =0A> > Th= ank you for this reply but I'm currently working=0A> under Linux with versi= on 1.5.0_15 of the JDK, well maybe my=0A> classpath variable is not correct= ly set; it is set as:=0A> /usr/share/jdbc/mysql-connector-java-5.1.6-bin.ja= r:/usr/share/tomcat/apache-tomcat-6.0.18/lib/servlet-api.jar=0A> > =0A> > S= omething is missing?? I don't know equivalent of=0A> \jarfiles\log4j-1.2.8.= jar under Linux=0A> > =0A> > Thank you for suggestions=0A> > Regards=0A> > = Michel=0A> > =0A> > On 4/19/09, Douglas Nelson =0A>= wrote:=0A> >> This is the classpath I set:=0A> >> =0A> >>=0A> classpath=3D= .;c:\;c:\download\java\commons-logging-1.0.4.jar;c:\jarfiles\log4j-1.2.8.ja= r;c:\jarfiles\mysql-connector-java-5.1.5-bin.jar;=0A> >> =0A> >> this is th= e code I use to connect to a MySql=0A> database=0A> >>=0A> //-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D=0A> >> // star= t getConnection=0A> >>=0A> //-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D=0A> >>=A0=A0=A0/**=0A> >>=A0 =A0 * Creates a n= ew connection to the=0A> database=0A> >>=A0 =A0 * @return the connection ob= ject=0A> >>=A0 =A0 */=0A> >>=A0=A0=A0private Connection=0A> getConnection()= throws Exception{=0A> >>=A0 =A0 =A0 logger.info("getConnection=0A> called"= );=0A> >>=A0 =A0 =A0 //------------------------=0A> >>=A0 =A0 =A0 // Load u= p the jdbc driver=0A> >>=A0 =A0 =A0 //------------------------=0A> >>=A0 = =A0 =A0 try {=0A> >>=A0 =A0 =A0=0A> =A0=A0=A0Class.forName("com.mysql.jdbc.= Driver").newInstance();=0A> >>=A0 =A0 =A0 } // end try=0A> >>=A0 =A0 =A0 ca= tch (Exception any) {=0A> >>=A0 =A0 =A0=0A> =A0=A0=A0logger.error("Unable t= o load driver. [" +=0A> any.getMessage() + "]");=0A> >>=A0 =A0 =A0 =A0=A0= =A0throw(any);=0A> >>=A0 =A0 =A0 } // end catch=0A> >> =0A> >>=A0 =A0 =A0= =0A> return(DriverManager.getConnection("jdbc:mysql://" +=0A> mysql_host += =0A> >> ":" + mysql_port +"/" + mysql_database + "?user=3D"=0A> + mysql_use= r +=0A> >> "&password=3D" + mysql_password));=0A> >> =0A> >>=A0=A0=A0} // e= nd getConnection=0A> >> =0A> >> =0A> >> =0A> >> Michel Maria-Sube wrote:=0A= > >>> hello,=0A> >>> =0A> >>> I'm working on an application connecting with= =0A> mysql5, considering that=0A> >>> $CLASSPATH is correctly set and piece= of code=0A> for connection is as=0A> >>> follows:=0A> >>> =0A> >>>=A0 =A0 = public void connectDB( String=0A> DBname, String user, String passwd ) {=0A= > >>>=A0 =A0 =A0 =A0 java.sql.Connection=0A> conn =3D null;=0A> >>>=A0 =A0 = =A0 =A0 String=A0 =A0=0A> url =3D null;=0A> >>> =0A> >>>=A0 =A0 =A0 =A0 try= {=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> Class.forName("com.mysql.jdbc.Driver"= ).newInstance();=0A> >>>=A0 =A0 =A0 =A0 }=0A> >>>=A0 =A0 =A0 =A0 catch=0A> = (ClassNotFoundException cnfe) {=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> System.o= ut.println("\nClassNotFoundException occured");=0A> >>>=A0 =A0 =A0 =A0 =A0 = =A0=0A> System.out.println("connection with the DB is not=0A> possible");= =0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> cnfe.printStackTrace();=0A> >>>=A0 =A0 = =A0 =A0 =A0 =A0=0A> System.exit(ERROR);=0A> >>>=A0 =A0 =A0 =A0 }=0A> >>>=A0= =A0 =A0 =A0 catch=0A> (InstantiationException ie) {=0A> >>>=A0 =A0 =A0 =A0= =A0 =A0=0A> System.out.println("InstantiationException occured");=0A> >>>= =A0 =A0 =A0 =A0 =A0 =A0=0A> System.out.println("connection with the DB is n= ot=0A> possible");=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> System.exit(ERROR);= =0A> >>>=A0 =A0 =A0 =A0 }=0A> >>>=A0 =A0 =A0 =A0 catch=0A> (IllegalAccessEx= ception iae) {=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> System.out.println("Illeg= alAccessException occured");=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0=0A> System.out.= println("connection with the DB is not=0A> possible");=0A> >>>=A0 =A0 =A0 = =A0 =A0 =A0=0A> System.exit(ERROR);=0A> >>>=A0 =A0 =A0 =A0 }=0A> >>>=A0 =A0= =A0 =A0 try {=0A> >>>=A0 =A0 =A0 =A0 =A0 =A0 url =3D=0A> new=0A> >>>=0A> S= tring("jdbc:mysql://localhost/"+DBname+"?user=3D"+user+"&password=3D"+passw= d);=0A> >>> .......................=0A> >>> =0A> >>> Execution gives follow= ing exception:=0A> >>> =0A> >>> ClassNotFoundException occured=0A> >>> conn= ection with the DB is not possible=0A> >>> java.lang.ClassNotFoundException= :=0A> com.mysql.jdbc.Driver=0A> >>>=A0 =A0 =A0 =A0 at=0A> java.net.URLClass= Loader$1.run(URLClassLoader.java:200)=0A> >>>=A0 =A0 =A0 =A0 at=0A> java.se= curity.AccessController.doPrivileged(Native Method)=0A> >>>=A0 =A0 =A0 =A0 = at=0A> java.net.URLClassLoader.findClass(URLClassLoader.java:188)=0A> >>>= =A0 =A0 =A0 =A0 at=0A> java.lang.ClassLoader.loadClass(ClassLoader.java:306= )=0A> >>>=A0 =A0 =A0 =A0 at=0A> sun.misc.Launcher$AppClassLoader.loadClass(= Launcher.java:276)=0A> >>>=A0 =A0 =A0 =A0 at=0A> java.lang.ClassLoader.load= Class(ClassLoader.java:251)=0A> >>>=A0 =A0 =A0 =A0 at=0A> java.lang.ClassLo= ader.loadClassInternal(ClassLoader.java:319)=0A> >>>=A0 =A0 =A0 =A0 at=0A> = java.lang.Class.forName0(Native Method)=0A> >>>=A0 =A0 =A0 =A0 at=0A> java.= lang.Class.forName(Class.java:169)=0A> >>>=A0 =A0 =A0 =A0 at=0A> MainFrame.= connectDB(MainFrame.java:290)=0A> >>>=A0 =A0 =A0 =A0 at=0A> MainFrame.creat= eMainScreen(MainFrame.java:260)=0A> >>>=A0 =A0 =A0 =A0 at=0A> MainFrame.(MainFrame.java:68)=0A> >>>=A0 =A0 =A0 =A0 at=0A> MainFrame.main(MainFra= me.java:1049)=0A> >>> =0A> >>> This behavior disapears if I update the jar= =0A> archive for executable with=0A> >>> classes content in the jdbc archiv= e but of=0A> course I don't want to do that;=0A> >>> does anybody could ind= icate me why java is=0A> anable to solve correctly paths=0A> >>> in the jdb= c archive?=0A> >>> =0A> >>> Thank you in advance=0A> >>> Regards=0A> >>> M.= =0A> > =0A> > --MySQL Java Mailing List=0A> > For list archives: http://lis= ts.mysql.com/java=0A> > To unsubscribe:=A0 =A0 http://lists.mysql.com/java?= unsub=3Dfederico_alcantara@stripped=0A> > =0A> =0A> Federico Alcantara=0A>= federico_alcantara@stripped=0A> =0A> =0A> =0A>