zoukankan      html  css  js  c++  java
  • java连接postgresql

    package  com.test;
     import  org.postgresql. * ;
     import  java.sql. * ;

     public   class  TestDB  {
        
     public  TestDB()  {
        }
     

        
     public   static   void  main(String args[])
        
     {
            System.out.print(
     " this is a test " );
            
     try 
             
     {
                Class.forName(
     " org.postgresql.Driver " ).newInstance();
                String url
     = " jdbc:postgresql://localhost:5432/postgres " ;
                Connection con
     = DriverManager.getConnection(url, " postgres " , " 1234 " );
                Statement st
     = con.createStatement();
                String sql
     = " select * from testtable " ;
                ResultSet rs
     = st.executeQuery(sql);
                
     while (rs.next())
                
     {
                    System.out.print(rs.getInt(
     1 ));
                    System.out.println(rs.getString(
     2 ));
                }
     

                rs.close();
                st.close();
                con.close();
                

            }
     

            
     catch (Exception ee)
            
     {
                System.out.print(ee.getMessage());
            }
     

        }
     

    }

  • 相关阅读:
    ubuntu安装ruby的几种方法总结
    使用一年ESB感受
    web工程迁移---在一个jboss5或jboss6中运行多个实例
    web工程迁移---weblogic8迁移到jboss5遇到的异常
    web工程迁移---jboss5迁移到jboss6
    Git使用(3)
    Git使用(2)
    Git使用(1)
    Spring4 mvc+maven 框架搭建(3)
    Spring4 mvc+maven 框架搭建(2)
  • 原文地址:https://www.cnblogs.com/zhaoxd/p/2959546.html
Copyright © 2011-2022 走看看