欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接

這篇文章給大家介紹postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

創(chuàng)新互聯(lián)憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗(yàn),為客戶(hù)提供超值的營(yíng)銷(xiāo)型網(wǎng)站建設(shè)服務(wù),我們始終認(rèn)為:好的營(yíng)銷(xiāo)型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個(gè)人等客戶(hù)提供了網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù),以良好的商業(yè)信譽(yù),完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。

1.下載驅(qū)動(dòng)jar

2.導(dǎo)入jar包

新建lib文件夾,將下載的jar驅(qū)動(dòng)包拖到文件夾中。

postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接

將jar驅(qū)動(dòng)包添加到Libraries

postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接

postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接

3.程序代碼如下:HelloWorld.java

package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class HelloWorld {
  public static void main(String []args) {
    Connection connection=null;
    Statement statement =null;
    try{
      String url="jdbc:postgresql://127.0.0.1:5432/postgis";
      String user="postgres";
      String password = "123456";
      Class.forName("org.postgresql.Driver");
      connection= DriverManager.getConnection(url, user, password);
      System.out.println("是否成功連接pg數(shù)據(jù)庫(kù)"+connection);
      String sql="select name from test";
      statement=connection.createStatement();
      ResultSet resultSet=statement.executeQuery(sql);
      while(resultSet.next()){
        String name=resultSet.getString(1);
        System.out.println(name);
      }
    }catch(Exception e){
      throw new RuntimeException(e);
    }finally{
      try{
        statement.close();
      }
      catch(SQLException e){
        e.printStackTrace();
        throw new RuntimeException(e);
      }finally{
        try{
          connection.close();
        }
        catch(SQLException e){
          e.printStackTrace();
          throw new RuntimeException(e);
        }
      }
    }
  }
}

運(yùn)行結(jié)果:

postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接

關(guān)于postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)站名稱(chēng):postgresql數(shù)據(jù)庫(kù)怎么利用Java進(jìn)行連接
文章路徑:http://www.chinadenli.net/article20/peigco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)商城網(wǎng)站軟件開(kāi)發(fā)品牌網(wǎng)站制作動(dòng)態(tài)網(wǎng)站微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)