|
|
刚开始用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); } }} |
|