1

I am using a postgresql database for my android app. i am new to developing android apps. I have added the postgresql.jar into the build path. However when i run the application i get Driver not found exception.

Could some one please help?

wanda
  • 61
  • 1
  • 1
  • 7
  • It means that you haven't added the library in the build path of your project. Also, how do you connect to the postre database in this architecture? AFAIK you should consume services and the server must contain the access/logic to handle the postgre (or another database) connectivity. – Luiggi Mendoza May 28 '13 at 19:38
  • i added to the build path by right clicking on the project in eclipse and adding external libraries. In eclipse i am using code : – wanda May 28 '13 at 20:28
  • try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { System.err .println("Driver not found: " + e + "\n" + e.getMessage()); } String uri = "jdbc:postgresql://db.doc.ic.ac.uk/rm3710?&ssl=true" ; Connection conn = null; try { conn = DriverManager.getConnection(uri, username,password); if(conn != null){ Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM Identity"); – wanda May 28 '13 at 20:30
  • Hi, i just explicitly copied the jar into the libs directory and when i run it now, i get-- "something unusual has caused the driver to fail." I am not sure what is going on with the postgresql driver – wanda May 28 '13 at 20:47
  • This is generally a bad idea. See http://stackoverflow.com/q/15853367/398670, http://stackoverflow.com/q/10435609/398670 – Craig Ringer May 29 '13 at 00:06
  • Hi, i am absolutely new to this and not sure how to develop a web service. is there no way i can use the postgresql directly in android as i have done with the swing version of my project? – wanda May 29 '13 at 09:43

1 Answers1

1

If the driver class is not found, because of some reasons the jar is still not in the path. Mind that jars must be in the folder called "libs", not "lib". If it will work as if nothing, that is another question, but the error message probably should be different.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
  • in eclipse i right clicked on the project and added to build path as external library the postgresql.jar and it appears not in the libs directory in eclipse but just after the Android private libraries. I am not sure how to add it to the build path as i clearly did it wrong. Could you help me through this? – wanda May 28 '13 at 20:27
  • Hi, i just explicitly copied the jar into the libs directory and when i run it now, i get-- "something unusual has caused the driver to fail. Uncaught exception." I am not sure what is going on with the postgresql driver – wanda May 28 '13 at 20:46
  • sorry, i have now checked the .classpath file and i see the postgresql.jar is in the lib folder. how do i move it to libs so that it is correctly added to class path? – wanda May 28 '13 at 21:04