• postgresql jdbc 连接数据库测试


    转载自:http://blog.csdn.net/southflow/article/details/5944107

    1. 下载postgresql-8.4-702.jdbc4.jar 
    2. 点击 project->properties 在弹出的对话框里点 Libraries 在右边点击 Add External JARs 然后选择jdbc的jar文件即可 
    3. 安装postgresql数据库,为了处理方便安装pgAdmin连接客户端。
    4. 编写测试程序:

    
    
    1. import org.postgresql.*;
    2. import java.sql.*;
    3. publicclassPostgresqlTest{
    4. /**
    5. * @param args
    6. */
    7. publicstaticvoid main(String[] args){
    8. // TODO Auto-generated method stub
    9. try{
    10. Class.forName("org.postgresql.Driver").newInstance();
    11. String connectUrl ="jdbc:postgresql://127.0.0.1:5432/postgres";
    12. Connection conn =DriverManager.getConnection(connectUrl,"postgres","sophie");
    13. Statement st = conn.createStatement();
    14. String sql =" SELECT 1;";
    15. ResultSet rs = st.executeQuery(sql);
    16. while(rs.next()){
    17. System.out.println(rs.getInt(1));
    18. }
    19. rs.close();
    20. st.close();
    21. conn.close();
    22. }catch(Exception e){
    23. e.printStackTrace();
    24. }
    25. }
    26. }

    5.运行程序输出 1

  • 相关阅读:
    {purple8}
    {purple7}
    {暴力}
    uva1103(dfs)
    {purple5练习题}
    c++复习题
    关于继承
    lrj紫书第五章
    20个Linux系统监视工具
    linux上配置jdk+Apache
  • 原文地址:https://www.cnblogs.com/yangcx666/p/8723765.html
Copyright © 2020-2023  润新知