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());
            }
     

        }
     

    }

  • 相关阅读:
    哈夫曼树
    MUI
    mui.init方法配置
    js中如何把字符串转化为对象、数组示例代码
    ( 转 )超级惊艳 10款HTML5动画特效推荐
    ( 转 ) 关于微信公众号,你不知道的15个小技巧
    h5预加载代码
    css3常用动画样式文件move.css
    iphone微信 h5页音乐自动播放
    sshpass: 用于非交互的ssh 密码验证
  • 原文地址:https://www.cnblogs.com/zhaoxd/p/2959546.html
Copyright © 2011-2022 走看看