Re: JDBC
От | Tim Freund |
---|---|
Тема | Re: JDBC |
Дата | |
Msg-id | 20010408181126.A23781@technofreund.com обсуждение исходный текст |
Ответ на | JDBC (Armin Preis <preisa@sbox.tugraz.at>) |
Список | pgsql-general |
I'll answer the code question last since you need a working classpath first... ;-) I pondered the class path issue for a long time. I will assume you are using bash or something similiar, since that's what I know -- make appropriate substitutions. To see your current CLASSPATH: echo $CLASSPATH To set your classpath: export CLASSPATH=/javadirectory/jarname.jar:/javadirectory/jar2.jar: To add your postgres jar onto your current classpath, do this: export CLASSPATH=$CLASSPATH:/usr/lib/pgsql/jdbc6.5-1.2.jar Alternatively, if all of your programs are going to use JDBC, you can copy jdbc6.5-1.2.jar to /usr/java/jdk1.3/jre/lib/ext -- that will automatically load the jdbc action on JVM start up. Let me know if you run into problems.... Tim -- /* Tim Freund -- tim@technofreund.com */ > Is the following code ok? Your code was close, but you were missing an org. in front of postgresql.Driver -- try this: import java.io.*; import java.lang.*; import java.sql.*; public class jdbcTest { public static void main(String args[]){ Connection con = null; String url = "jdbc:postgresql:dbname"; String username = "username"; String password = "password"; try{ Class.forName("org.postgresql.Driver"); con = DriverManager.getConnection(url, username, password); } catch(SQLException e){ e.printStackTrace(System.out); } catch(ClassNotFoundException e){ e.printStackTrace(System.out); } } }
В списке pgsql-general по дате отправления: