Re: Exception Error - Please help I've tried everything!
От | Reuben Pasquini |
---|---|
Тема | Re: Exception Error - Please help I've tried everything! |
Дата | |
Msg-id | 4E2EF297-8357-4BA6-9609-C84ECD0BDDEF@bellsouth.net обсуждение исходный текст |
Ответ на | Exception Error - Please help I've tried everything! ("Greg Peters" <gregpeters79@gmail.com>) |
Список | pgsql-jdbc |
Hi Greg, Here are a couple ideas. *. You can verify that you have a good jar file by running: jar tf postgresql.jar - org.postgresql.Driver should be listed in the jar contents. *. You're launching your app with the wrong command line: $ java -cp postgresql.jar PostgresqlClient.class Exception in thread "main" java.lang.NoClassDefFoundError: PostgresqlClient/class Use this instead: $ java -cp postgresql.jar:. PostgresqlClient Exception in thread "main" java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:545) at java.sql.DriverManager.getConnection(DriverManager.java:171) at PostgresqlClient.main(PostgresqlClient.java:15) Finally - that last error is because you're using an incorrectly formatted URL. Set String url = "jdbc:postgresql:littleware://localhost: 5432"; $ javac PostgresqlClient.java I don't have a 'root' user - but this will hopefully get you a little closer ... $ java -cp postgresql.jar:. PostgresqlClient Exception in thread "main" org.postgresql.util.PSQLException: FATAL: role "root" does not exist at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages (ConnectionFactoryImpl.java:443) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl (ConnectionFactoryImpl.java:98) at org.postgresql.core.ConnectionFactory.openConnection (ConnectionFactory.java:65) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init> (AbstractJdbc2Connection.java:116) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init> (AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3.Jdbc3Connection.<init> (Jdbc3Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:369) at org.postgresql.Driver.connect(Driver.java:245) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at PostgresqlClient.main(PostgresqlClient.java:15) On Nov 26, 2006, at 1:48 AM, Greg Peters wrote: > Hello all, > > I'm trying to get the following simple program to run just to > confirm a connection to the database: > > //PostgresqlClient.java > import java.sql.*; > > public class PostgresqlClient{ > public static void main(String[] arguments) > throws ClassNotFoundException, SQLException{ > > String driver = "org.postgresql.Driver"; > String url ="localhost"; > String user = "root"; > String pwd = "password"; > > Class.forName(driver); > > Connection con = DriverManager.getConnection(url, user, pwd); > System.err.println("Connection complete"); > > con.close(); > } > } > > > I keep getting the folowing errors: > > Exception in thread "main" java.lang.ClassNotFoundException: > org.postgresql.Driver > at java.net.URLClassLoader$1.run(URLClassLoader.java:200) > at java.security.AccessController.doPrivileged (Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:188) > at java.lang.ClassLoader.loadClass(ClassLoader.java:306) > at sun.misc.Launcher$AppClassLoader.loadClass > (Launcher.java :268) > at java.lang.ClassLoader.loadClass(ClassLoader.java:251) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java: > 319) > at java.lang.Class.forName0(Native Method) > at java.lang.Class.forName (Class.java:164) > at PostgresqlClient.main(PostgresqlClient.java:12) > Java Result: 1 > BUILD SUCCESSFUL (total time: 0 seconds) > > I have tried adding the postgresql.jar file to my CLASSPATH, and > have also tried copying the postgresql.jar file to the same > directory as the PostgresqlClient.java and PostgresqlClient.class > directories. I have also tried running the following from the > command line: > > java -classpath postgresql.jar PostgresqlClient.class > > I am using jdk1.5.0_09 and have tried using nearly all the > available postgresql.jar files available. > > Any advice would be most appreciated. > > Cheers, > > Greg Peters.... > > > > > > >
В списке pgsql-jdbc по дате отправления:
Предыдущее
От: "Greg Peters"Дата:
Сообщение: Re: Exception Error - Please help I've tried everything!