java - Loading the postgreSQL JDBC driver -


i trying load jdbc postgresql driver java program. know on internet. have tried many solutions, none of them have worked me.

the problem error:

exception in thread "main" java.lang.noclassdeffounderror:     classes/com/freire/test/jdbcexample/class caused by: java.lang.classnotfoundexception: classes.com.freire.test.jdbcexample.class @ java.net.urlclassloader$1.run(urlclassloader.java:202) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:190) @ java.lang.classloader.loadclass(classloader.java:306) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:301) @ java.lang.classloader.loadclass(classloader.java:247) 

and code looks this:

package com.freire.test; import java.sql.drivermanager; import java.sql.connection; import java.sql.sqlexception;  public class jdbcexample  {     public static void main(string[] argv)      {         system.out.println("jdbc connection testing");         try {             class.forname("org.postgresql.driver");         } catch (classnotfoundexception e) {             system.out.println("postgresql jdbc driver not included!");         }     } } 

and structure of project looks this:

myproject  src    com      freire        test          jdbcexample.java  classes    com      freire        test          jdbcexample.class  lib    postgresql-9.2-1003.jdbc3.jar 

compiling works fine:

java -d classes/ src/com/freire/test/jdbcexample.java 

but executing produces error:

java classes/com/freire/test/jdbcexample 

worth working on os x mountain lion.

any appreciated.

firstly need mention package names using . instead of / while running java program:

go classes directory , run jdbcexample :

java com.freire.test.jdbcexample 

but cry postgres driver class not found because postgres jar missing in classpath.so need use classpath option while running program , add postgres jar classpath:

for windows:

java -cp .;../lib/postgresql-9.2-1003.jdbc3.jar com.freire.test.jdbcexample 

for linux:

java -cp .:../lib/postgresql-9.2-1003.jdbc3.jar com.freire.test.jdbcexample 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -