List of usage examples for java.sql ResultSet close
void close() throws SQLException;
ResultSet
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); conn.setAutoCommit(false); // start a transaction Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'nameValue')"); conn.rollback(); // the preceding inserts will not commit; st.executeUpdate("INSERT INTO survey(id, name) VALUES('33', 'jeff')"); conn.commit(); // end the transaction st = conn.createStatement();//w w w . j ava2s . co m ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myDate DATE);"); String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); pstmt.setNull(2, java.sql.Types.DATE); pstmt.executeUpdate();/*www . j a v a2s . c o m*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myURL CHAR);"); String INSERT_RECORD = "insert into survey(id, myURL) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); pstmt.setURL(2, new URL("http://www.java2s.com")); pstmt.executeUpdate();// www . j av a 2 s. com ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myDate TIMESTAMP );"); String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(2, sqlDate);/*w ww . ja v a 2 s. c o m*/ pstmt.executeUpdate(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myDate DATE);"); String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime()); pstmt.setDate(2, sqlDate);/*w w w. ja v a2 s . com*/ pstmt.executeUpdate(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myDate TIME);"); String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); java.sql.Time sqlDate = new java.sql.Time(new java.util.Date().getTime()); pstmt.setTime(2, sqlDate);/*from w w w . j av a2 s .co m*/ pstmt.executeUpdate(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false);//ww w . ja v a 2 s . c o m Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int, name VARCHAR(30) );"); String INSERT_RECORD = "insert into survey(id, name) values(?,?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); for (int i = 0; i < 10; i++) { pstmt.setInt(1, i); pstmt.setString(2, "name" + i); pstmt.executeUpdate(); } ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn = null;// w ww . j ava2 s. c o m Properties info = new Properties(); // info.put("proxy_type", "4"); // SSL Tunneling info.put("proxy_host", "[proxy host]"); info.put("proxy_port", "[proxy port]"); info.put("proxy_user", "[proxy user]"); info.put("proxy_password", "[proxy password]"); info.put("user", "[db user]"); info.put("password", "[db pass word]"); conn = DriverManager.getConnection("jdbc:mysql://[db host]/", info); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("Select NOW()"); rs.next(); System.out.println("Data- " + rs.getString(1)); rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); conn.setAutoCommit(false);//from ww w .j a v a2s.c om Statement st = conn.createStatement(); try { st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'nameValue')"); // commits all the transactions conn.commit(); } catch (Exception e) { //cancel (roll back) all the transactions conn.rollback(); // to see what went wrong e.printStackTrace(); } st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false);//from ww w . ja v a2s . co m Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int, name VARCHAR(30) );"); String INSERT_RECORD = "insert into survey(id, name) values(?,?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); pstmt.setString(2, "name1"); pstmt.addBatch(); pstmt.setString(1, "2"); pstmt.setString(2, "name2"); pstmt.addBatch(); int[] updateCounts = pstmt.executeBatch(); checkUpdateCounts(updateCounts); conn.commit(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }