1 2 3 Previous Next 35 Replies Latest reply: Mar 7, 2007 7:44 AM by 807606 RSS

    Connecting to a database (Linux - Debian)

    801447
      Hi. This one has me completely confused.

      Im trying to connect to a mdb in debian, but the code only works in windows.

      this code here works in windows:
      try {
                     String chemin = "Database\Elcire.mdb";
                     String fullConnectionString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + chemin;
                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                     conn = DriverManager.getConnection(fullConnectionString);
                     System.out.println("Connected To SQL Server");
                } catch(Exception e) {
                     e.printStackTrace();
                }
      but in Debian, i get this error:
      java.lang.NullPointerException
              at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source)
              at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
              at java.sql.DriverManager.getConnection(Unknown Source)
              at java.sql.DriverManager.getConnection(Unknown Source)
              at Server.<init>(Server.java:58)
              at Server.main(Server.java:33)
      I have no clue why it might not be working.
      The only thing that i can think of is me having to change the directory format to something else, which still isnt any help cause i have no clue what to change it do.
      any help is really appreciated.

      Thanks for your time,
      Mockers
        • 1. Re: Connecting to a database (Linux - Debian)
          807606
          Hmm normally this shouldn't compile without errors:
          String chemin = "Database\Elcire.mdb";
          because you have to escape the backslash '\' like this:
          String chemin = "Database\\Elcire.mdb";
          On Linux the path seperator is not the backslash...it is the slash '/'

          Maybe you try:
          String chemin = "Database/Elcire.mdb";
          Note that you don't have to escape the slash!
          I would also check the path to the file.....if it is in let's say:
          /home/user/Database/Elcire.mbd than you should edit your code accordingly.


          Otherwise I would suggest that maybe the driver is not the correct one?
          But I am not sure on that....




          hope that helps....

          regards....

          Message was edited by:
          n3bul4
          • 2. Re: Connecting to a database (Linux - Debian)
            807606
            My guess: you have neither ODBC running nor a Microsoft Access ODBC driver installed on your non-Windows machine ...
            • 3. Re: Connecting to a database (Linux - Debian)
              801447
              good point... is it possible to install the mdb driver on a linux machine?

              btw, i just quickly edited those slashes in as i had it as something else.

              ur not going to believe this, but the database is located here:
              elcire/Elcire/Elcire/Elcire/Database/Elcire.mdb
              edit:
              if i cant use that database, i have a mysql 1 running which i cant figure out how to connect too.
              Can anyone help me with this one?

              Message was edited by:
              Futurisdom_Developer
              • 4. Re: Connecting to a database (Linux - Debian)
                807606
                The last time I installed ODBC on a Linux machine, I got sick of it ... it might have improved since then, though. Not sure about Access drivers for Linux, but I'd try to replace Access by another DBMS ...
                • 5. Re: Connecting to a database (Linux - Debian)
                  801447
                  alrighty then lets forget the microsoft database.

                  I found an example of connecting to a mysql database, but i got a class not found exception.
                  Ill get the error message for ya in a sec.
                  java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
                          at java.net.URLClassLoader$1.run(Unknown Source)
                          at java.security.AccessController.doPrivileged(Native Method)
                          at java.net.URLClassLoader.findClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                          at java.lang.Class.forName0(Native Method)
                          at java.lang.Class.forName(Unknown Source)
                          at Server.<init>(Server.java:47)
                          at Server.main(Server.java:33)
                  and heres my code
                                 Class.forName("com.mysql.jdbc.Driver").newInstance();
                                 conn = DriverManager.getConnection("jdbc:mysql://localhost/elcire", "#####","#####");
                  • 6. Re: Connecting to a database (Linux - Debian)
                    807606
                    Download the mysql driver package and put it into your classpath.

                    http://dev.mysql.com/downloads/connector/j/3.1.html
                    • 7. Re: Connecting to a database (Linux - Debian)
                      807606
                      The program can not find the JDBC - Driver witch is needed to
                      connect to the mysql database.

                      You have to download the jdbc mysql driver and put it into your classpath,
                      so that java can find it....


                      regards---
                      • 8. Re: Connecting to a database (Linux - Debian)
                        801447
                        ahh i c.

                        ... whats the classpath? im guessing its the lib folder but i wouldnt bet my life on it
                        • 9. Re: Connecting to a database (Linux - Debian)
                          807606
                          Maybe you try this:

                          My java is installed into: /usr/lib/jvm/sun-jdk-1.6/

                          Threre is a subfolder 'lib' (/usr/lib/jvm/sun-jdk-1.6/lib/)
                          You can download the jdbc driver extract the files and locate the .jar in it.
                          Copy this .jar file to the lib directory.....should work.....


                          regards
                          • 10. Re: Connecting to a database (Linux - Debian)
                            801447
                            thanks allot. Ill post back if it works/doenst work...so ill post back no matter what :P
                            • 11. Re: Connecting to a database (Linux - Debian)
                              801447
                              didnt work.

                              i put the jar file here:
                              /usr/lib/j2re1.5-sun/lib
                              but i still got the same error
                              java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
                                      at java.net.URLClassLoader$1.run(Unknown Source)
                                      at java.security.AccessController.doPrivileged(Native Method)
                                      at java.net.URLClassLoader.findClass(Unknown Source)
                                      at java.lang.ClassLoader.loadClass(Unknown Source)
                                      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                                      at java.lang.ClassLoader.loadClass(Unknown Source)
                                      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                                      at java.lang.Class.forName0(Native Method)
                                      at java.lang.Class.forName(Unknown Source)
                                      at Server.<init>(Server.java:47)
                                      at Server.main(Server.java:33)
                              the jar file is named mysql-connector-java-3.1.14-bin.jar. is it supposed to be named something different?

                              thanks.
                              • 12. Re: Connecting to a database (Linux - Debian)
                                807606
                                Hmm I see...


                                Does the output of:
                                n3bul4@Omega ~ $ java -version
                                java version "1.6.0"
                                Java(TM) SE Runtime Environment (build 1.6.0-b105)
                                Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)
                                contain the same version string than the directory?
                                Maybe you have more than one virtual machine running?

                                regards....
                                • 13. Re: Connecting to a database (Linux - Debian)
                                  801447
                                  I see what you mean, altho i dont see how i could have more than 1 running. i maped a network drive from my windows computer and searched it, and the only .jar files that came up where in that directory. heres the directory listing:
                                  root@GlenServer:/usr/lib/j2re1.5-sun/lib# ls
                                  applet                                fontconfig.RedHat.bfc                jsse.jar
                                  audio                                 fontconfig.RedHat.properties.src     jvm.hprof.txt
                                  charsets.jar                          fontconfig.Sun.2003.bfc              locale
                                  classlist                             fontconfig.Sun.2003.properties.src   logging.properties
                                  cmm                                   fontconfig.Sun.bfc                   management
                                  content-types.properties              fontconfig.Sun.properties.src        mysql-connector-java-3.1.14
                                  deploy.jar                            fontconfig.SuSE.bfc                  mysql-connector-java-3.1.14-bin.jar
                                  ext                                   fontconfig.SuSE.properties.src       mysql-connector-java-3.1.14.tar
                                  flavormap.properties                  fontconfig.Turbo.8.0.bfc             net.properties
                                  fontconfig.bfc                        fontconfig.Turbo.8.0.properties.src  oblique-fonts
                                  fontconfig.properties.src             fontconfig.Turbo.bfc                 plugin.jar
                                  fontconfig.RedHat.2.1.bfc             fontconfig.Turbo.properties.src      psfontj2d.properties
                                  fontconfig.RedHat.2.1.properties.src  fonts                                psfont.properties.ja
                                  fontconfig.RedHat.3.bfc               i386                                 rt.jar
                                  fontconfig.RedHat.3.properties.src    im                                   security
                                  fontconfig.RedHat.8.0.bfc             images                               sound.properties
                                  fontconfig.RedHat.8.0.properties.src  javaws                               zi
                                  fontconfig.RedHat.9.0.bfc             javaws.jar
                                  fontconfig.RedHat.9.0.properties.src  jce.jar
                                  and this is my java version:
                                  java version "1.5.0_11"
                                  • 14. Re: Connecting to a database (Linux - Debian)
                                    807606
                                    Hmm I am not sure if I get you rigth.....

                                    Do you mean you are using a windows vm mounted into your linux system?
                                    This won't work because you have to use the linux vm on linux....
                                    Sry if I got you wrong here....

                                    try to enter the command: java -version in your system shell...
                                    What does it say?
                                    It is possible that more than one vm is installed on your linux box already.....but this is just an asumption.
                                    1 2 3 Previous Next