postgresql安装
发布时间:2020-12-13 18:12:13 所属栏目:百科 来源:网络整理
导读:下载postgresql数据库 sudo su - postgres 切换到postgres用户,下载安装数据库后自带的用户,默认密码为空 psql 登录到控制台 password postgres 给postgresql设置密码 q 退出 创建数据库和数据表 测试连接,代码如下,需要导入对应的的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()); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |