加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql安装

发布时间:2020-12-13 18:12:13 所属栏目:百科 来源:网络整理
导读:下载postgresql数据库 sudo su - postgres 切换到postgres用户,下载安装数据库后自带的用户,默认密码为空 psql 登录到控制台 password postgres 给postgresql设置密码 q 退出 创建数据库和数据表 测试连接,代码如下,需要导入对应的的jdbc,输入数据库
  1. 下载postgresql数据库

  2. sudo su - postgres

    切换到postgres用户,下载安装数据库后自带的用户,默认密码为空

  3. psql

    登录到控制台

  4. password postgres

    给postgresql设置密码

  5. q

    退出

  6. 创建数据库和数据表

  7. 测试连接,代码如下,需要导入对应的的jdbc,输入数据库对应内容则成功。

importorg.postgresql.*;
importjava.sql.*;
publicclassDemo{
publicstaticvoidmain(String[]args){
try{
Class.forName("org.postgresql.Driver").newInstance();
Stringurl="jdbc:postgresql://localhost:5432/extdb";
Connectioncon=DriverManager.getConnection(url,"postgres","postgres");
Statementst=con.createStatement();
Stringsql="select*frominfo";
ResultSetrs=st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString(1));
}
rs.close();
st.close();
}
catch(Exceptionee)
{
System.out.println(ee.getMessage());
}

}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读