Error:java.lang.ClassNotFoundException: org.postgresql.Driver
Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
Nithin Chakravarthi <nithin@embdestech.co.in>
Дата:
Hi All,
I am working on java project to insert and fetch data from postgresql database. While using jbdc I am getting error"java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at SqlConnection.sql_connection(SqlConnection.java:29)
at ServerConnection.run(ServerConnection.java:205)
at java.lang.Thread.run(Thread.java:745)
"
"jdbc:postgresql://127.0.0.1:5432/testdb";
public int sql_connection(String outletid, String messageid, String checkid,int msgarry,String message,PrintStream os)
{
String []lines = message.split("\\?");
String [] separated = lines[0].split("\\|");
//for(int i=0;i<4;i++)
//System.out.println("received msg from client :"+separated[i]);
msgformation pack = new msgformation();
System.out.println("sizes---: " +separated.length+" ---Arry Received: "+ msgarry);
if(separated.length==msgarry){
try{
System.out.println("Connecting to database...");
Properties password = new Properties();
password.put("user","postgress");
password.put("password","postgress");
password.put("host","localhost");
Class.forName("org.postgresql.Driver");
//DriverManager.register(org.postgresql.Driver());
ServerMain.conn = DriverManager.getConnection(DB_URL,password);
"
"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"
Server.jar is main executable file.
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
Álvaro Hernández Tortosa <aht@8kdata.com>
Дата:
IMVHO, I completely got rid of issues like this when I started using Maven (or Gradle or equivalent).
I'd recommend you to do the same (and by the way, use a more modern version of the driver).
Álvaro
-- Álvaro Hernández Tortosa ----------- 8Kdata
On 29/03/16 13:04, Nithin Chakravarthi wrote:
So please help me to solve this issue.I have exported class path as"private static final String DB_URL =Here is my srcFYI I am using multiple source files. Main function is defined in one file and I am using postgresql connection in another fileHi All,I am working on java project to insert and fetch data from postgresql database. While using jbdc I am getting error
"java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at SqlConnection.sql_connection(SqlConnection.java:29)
at ServerConnection.run(ServerConnection.java:205)
at java.lang.Thread.run(Thread.java:745)
"
"jdbc:postgresql://127.0.0.1:5432/testdb";
public int sql_connection(String outletid, String messageid, String checkid,int msgarry,String message,PrintStream os)
{
String []lines = message.split("\\?");
String [] separated = lines[0].split("\\|");
//for(int i=0;i<4;i++)
//System.out.println("received msg from client :"+separated[i]);
msgformation pack = new msgformation();
System.out.println("sizes---: " +separated.length+" ---Arry Received: "+ msgarry);
if(separated.length==msgarry){
try{
System.out.println("Connecting to database...");
Properties password = new Properties();
password.put("user","postgress");
password.put("password","postgress");
password.put("host","localhost");
Class.forName("org.postgresql.Driver");
//DriverManager.register(org.postgresql.Driver());
ServerMain.conn = DriverManager.getConnection(DB_URL,password);
"
"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"
Server.jar is main executable file.
Re: Error:java.lang.ClassNotFoundException:org.postgresql.Driver
От:
Álvaro Hernández Tortosa <aht@8kdata.com>
Дата:
IMVHO, I completely got rid of issues like this when I started using Maven (or Gradle or equivalent).
I'd recommend you to do the same (and by the way, use a more modern version of the driver).
Álvaro
-- Álvaro Hernández Tortosa ----------- 8Kdata
On 29/03/16 13:04, Nithin Chakravarthi wrote:
So please help me to solve this issue.I have exported class path as"private static final String DB_URL =Here is my srcFYI I am using multiple source files. Main function is defined in one file and I am using postgresql connection in another fileHi All,I am working on java project to insert and fetch data from postgresql database. While using jbdc I am getting error
"java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at SqlConnection.sql_connection(SqlConnection.java:29)
at ServerConnection.run(ServerConnection.java:205)
at java.lang.Thread.run(Thread.java:745)
"
"jdbc:postgresql://127.0.0.1:5432/testdb";
public int sql_connection(String outletid, String messageid, String checkid,int msgarry,String message,PrintStream os)
{
String []lines = message.split("\\?");
String [] separated = lines[0].split("\\|");
//for(int i=0;i<4;i++)
//System.out.println("received msg from client :"+separated[i]);
msgformation pack = new msgformation();
System.out.println("sizes---: " +separated.length+" ---Arry Received: "+ msgarry);
if(separated.length==msgarry){
try{
System.out.println("Connecting to database...");
Properties password = new Properties();
password.put("user","postgress");
password.put("password","postgress");
password.put("host","localhost");
Class.forName("org.postgresql.Driver");
//DriverManager.register(org.postgresql.Driver());
ServerMain.conn = DriverManager.getConnection(DB_URL,password);
"
"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"
Server.jar is main executable file.
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
danap <danap@itstriangle.com>
Дата:
Nithin Chakravarthi wrote:
> Hi All,
>
> I am working on java project to insert and fetch data from postgresql database.
> While using jbdc I am getting error
>
> "*java.lang.ClassNotFoundException: org.postgresql.Driver
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>
> ~
> ~
> ~
>
> //DriverManager.register(org.postgresql.Driver());
> ServerMain.conn =
> DriverManager.getConnection(DB_URL,password);
>
> "
> *
> I have exported class path as
>
> *"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"
> *
>
> Server.jar is main executable file.
>
> So please help me to solve this issue.
> //
> Thanks & Regards,
> *M. Nithin Chakravrthi*
> Software Engineer
Hello Nithin,
Yes you can use Maven or other to build your jar or can
use the basics which is valuable in understanding the
process by compiling directly, and creating the jar
with the commands, javac, jar. Insure these are on your
execution path.
See Example Files:
https://github.com/danap/myjsqlview
make, build, myjsqlview.mf
make - Compiles your source files to the specified directly.
Use the -classpath to defines libraries, jars, required
in the compile.
build - Creates your jar file with included jars, your case
and other files.
myjsqlview.mf - specifiy the inclusion here the main class and
required jar, postgresql driver here.
Use the .bat files for Win, .sh for Unix/Linux.
Alternative, just place the postgresql driver in the jre/lib/ext
folder.
danap.
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
"M. Dietrich" <mdt@emdete.de>
Дата:
Zitat aus Nithin Chakravarthi's Nachricht : > *"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"* java does not expand the "~" denoting your home dir, use `pwd` instead to let the shell do that or name the full filename with absolute directory.
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
John R Pierce <pierce@hogranch.com>
Дата:
On 3/29/2016 12:16 PM, M. Dietrich wrote:
> Zitat aus Nithin Chakravarthi's Nachricht :
>> *"export
>> CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"*
>
> java does not expand the "~" denoting your home dir, use `pwd`
> instead to let the shell do that or name the full filename
> with absolute directory.
I'd suggest:
export
CLASSPATH=./Server.jar:$HOME/Downloads/postgresql-9.3-1103.jdbc3.jar
that $HOME will get expanded when the 'set' is being done, so the value
of $CLASSPATH will contain ...:/home/whatever/Downloads/...
--
john r pierce, recycling bits in santa cruz
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
danap <danap@itstriangle.com>
Дата:
Nithin Chakravarthi wrote:
> Hi All,
>
> I am working on java project to insert and fetch data from postgresql database.
> While using jbdc I am getting error
>
> "*java.lang.ClassNotFoundException: org.postgresql.Driver
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>
> ~
> ~
> ~
>
> //DriverManager.register(org.postgresql.Driver());
> ServerMain.conn =
> DriverManager.getConnection(DB_URL,password);
>
> "
> *
> I have exported class path as
>
> *"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"
> *
>
> Server.jar is main executable file.
>
> So please help me to solve this issue.
> //
> Thanks & Regards,
> *M. Nithin Chakravrthi*
> Software Engineer
Hello Nithin,
Yes you can use Maven or other to build your jar or can
use the basics which is valuable in understanding the
process by compiling directly, and creating the jar
with the commands, javac, jar. Insure these are on your
execution path.
See Example Files:
https://github.com/danap/myjsqlview
make, build, myjsqlview.mf
make - Compiles your source files to the specified directly.
Use the -classpath to defines libraries, jars, required
in the compile.
build - Creates your jar file with included jars, your case
and other files.
myjsqlview.mf - specifiy the inclusion here the main class and
required jar, postgresql driver here.
Use the .bat files for Win, .sh for Unix/Linux.
Alternative, just place the postgresql driver in the jre/lib/ext
folder.
danap.
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
"M. Dietrich" <mdt@emdete.de>
Дата:
Zitat aus Nithin Chakravarthi's Nachricht : > *"export CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"* java does not expand the "~" denoting your home dir, use `pwd` instead to let the shell do that or name the full filename with absolute directory.
Re: Error:java.lang.ClassNotFoundException:org.postgresql.Driver
От:
John R Pierce <pierce@hogranch.com>
Дата:
On 3/29/2016 12:16 PM, M. Dietrich wrote:
> Zitat aus Nithin Chakravarthi's Nachricht :
>> *"export
>> CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"*
>
> java does not expand the "~" denoting your home dir, use `pwd`
> instead to let the shell do that or name the full filename
> with absolute directory.
I'd suggest:
export
CLASSPATH=./Server.jar:$HOME/Downloads/postgresql-9.3-1103.jdbc3.jar
that $HOME will get expanded when the 'set' is being done, so the value
of $CLASSPATH will contain ...:/home/whatever/Downloads/...
--
john r pierce, recycling bits in santa cruz
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
"M. Dietrich" <mdt@emdete.de>
Дата:
Zitat aus John R Pierce's Nachricht : > On 3/29/2016 12:16 PM, M. Dietrich wrote: >> Zitat aus Nithin Chakravarthi's Nachricht : >>> *"export >>> CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"* >> java does not expand the "~" denoting your home dir, use `pwd` >> instead to let the shell do that or name the full filename >> with absolute directory. > I'd suggest: > > export CLASSPATH=./Server.jar:$HOME/Downloads/postgresql-9.3-1103.jdbc3.jar > > that $HOME will get expanded when the 'set' is being done, so the value > of $CLASSPATH will contain ...:/home/whatever/Downloads/... correct, pwd does not do the job, sorry ;)
Re: Error:java.lang.ClassNotFoundException: org.postgresql.Driver
От:
"M. Dietrich" <mdt@emdete.de>
Дата:
Zitat aus John R Pierce's Nachricht : > On 3/29/2016 12:16 PM, M. Dietrich wrote: >> Zitat aus Nithin Chakravarthi's Nachricht : >>> *"export >>> CLASSPATH=./Server.jar:~/Downloads/postgresql-9.3-1103.jdbc3.jar"* >> java does not expand the "~" denoting your home dir, use `pwd` >> instead to let the shell do that or name the full filename >> with absolute directory. > I'd suggest: > > export CLASSPATH=./Server.jar:$HOME/Downloads/postgresql-9.3-1103.jdbc3.jar > > that $HOME will get expanded when the 'set' is being done, so the value > of $CLASSPATH will contain ...:/home/whatever/Downloads/... correct, pwd does not do the job, sorry ;)