六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 144|回复: 0

用JDBC连接Postgres(Postgres学习笔记1)

[复制链接]

升级  34.33%

87

主题

87

主题

87

主题

举人

Rank: 3Rank: 3

积分
303
 楼主| 发表于 2013-1-30 01:31:36 | 显示全部楼层 |阅读模式
刚开始用Postgres。。
 
package Utils;import java.sql.*;import  org.postgresql. *;public class PostgrelDemo {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/mydb_1" ;           Connection con = DriverManager.getConnection(url, "postgres" , "1234" );           //String sql = " select * from students" ;           String sql = "insert into students (id,name) values(?,?)";          // ResultSet rs = st.executeQuery(sql);          //  while (rs.next())            //{             //  System.out.print(rs.getInt( 1 ));              // System.out.println(rs.getString( 2 ));         //  }         //  rs.close();           PreparedStatement pstmt = con.prepareStatement(sql);pstmt.setInt(1, 1225);pstmt.setString(2, "Nicole.rabbit");pstmt.executeUpdate();           pstmt.close();           con.close();       }        catch (Exception ee)        {           System.out.print("error at "+ee);       }   }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表