List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:Main.java
public static void getTables(Connection conn) throws Exception { String TABLE_NAME = "TABLE_NAME"; String TABLE_SCHEMA = "TABLE_SCHEM"; String[] TABLE_AND_VIEW_TYPES = { "TABLE", "VIEW" }; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables(null, null, null, TABLE_AND_VIEW_TYPES); while (tables.next()) { System.out.println(tables.getString(TABLE_NAME)); System.out.println(tables.getString(TABLE_SCHEMA)); }/*from www. j a v a 2s .c om*/ }
From source file:SerializeJavaObjects_MySQL.java
public static Object readJavaObject(Connection conn, long id) throws Exception { PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id);/*w w w. j a va 2s . c o m*/ ResultSet rs = pstmt.executeQuery(); rs.next(); Object object = rs.getObject(1); String className = object.getClass().getName(); rs.close(); pstmt.close(); System.out.println("readJavaObject: done de-serializing: " + className); return object; }
From source file:com.dbconnection.DataSourceConnection.java
private static String query(Connection connection) throws SQLException { String query = ""; Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM BOOK"); while (resultSet.next()) { int id = resultSet.getInt("id"); String title = resultSet.getString("title"); query = query + id + "\t" + title + "\n"; }/* w w w. j a v a 2s .com*/ return query; }
From source file:MainClass.java
public static void readDatabase() { String data = "jdbc:derby:presidents"; try {//from w ww . ja v a2s.c o m Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection conn = DriverManager.getConnection(data, "", ""); Statement st = conn.createStatement(); ResultSet rec = st.executeQuery("SELECT * FROM contacts ORDER BY name"); while (rec.next()) { System.out.println( rec.getString("name") + "\n" + rec.getString("address1") + "\n" + rec.getString("address2") + "\n" + rec.getString("phone") + "\n" + rec.getString("email") + "\n"); } st.close(); } catch (Exception e) { System.out.println("Error - " + e.toString()); } }
From source file:Main.java
public static long writeJavaObject(Connection conn, Object object) throws Exception { String className = object.getClass().getName(); PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL); pstmt.setString(1, className);/*from w ww . j av a 2 s . com*/ pstmt.setObject(2, object); pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); int id = -1; if (rs.next()) { id = rs.getInt(1); } rs.close(); pstmt.close(); return id; }
From source file:com.pinterest.deployservice.db.SingleResultSetHandlerFactory.java
public static <T> ResultSetHandler<T> newObjectHandler() { return new ResultSetHandler<T>() { @Override/*w w w . ja v a 2 s . co m*/ public T handle(ResultSet resultSet) throws SQLException { if (resultSet.next()) { return (T) resultSet.getObject(1); } return null; } }; }
From source file:SerializeJavaObjects_MySQL.java
public static long writeJavaObject(Connection conn, Object object) throws Exception { String className = object.getClass().getName(); PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL); // set input parameters pstmt.setString(1, className);// ww w .j a v a2 s. c o m pstmt.setObject(2, object); pstmt.executeUpdate(); // get the generated key for the id ResultSet rs = pstmt.getGeneratedKeys(); int id = -1; if (rs.next()) { id = rs.getInt(1); } rs.close(); pstmt.close(); System.out.println("writeJavaObject: done serializing: " + className); return id; }
From source file:Main.java
public static long[] getEntryExit(Double id, Calendar date, Connection con, PreparedStatement stmt) throws Exception { stmt.setDate(1, new java.sql.Date(date.getTimeInMillis())); // stmt.setDate(2, new java.sql.Date(date.getTimeInMillis()+1000000)); stmt.execute();/*from www . j a v a 2 s .c o m*/ ResultSet rs = stmt.getResultSet(); if (rs != null) { if (rs.next()) { Timestamp d1 = rs.getTimestamp(1); Timestamp d2 = rs.getTimestamp(2); if (d1 != null && d2 != null) { System.out.println(id + ":" + new SimpleDateFormat("dd/MM/yyyy").format(date.getTime()) + ":" + d1.toString()); long[] res = new long[] { d1.getTime(), d2.getTime() }; return res; } } rs.close(); } return null; }
From source file:com.l2jfree.gameserver.datatables.PetNameTable.java
public static boolean doesPetNameExist(String name, int petNpcId) { boolean result = true; Connection con = null;/* w ww . j a va 2s . c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id=?"); statement.setString(1, name); statement.setString(2, Integer.toString(PetDataTable.getItemIdByPetId(petNpcId))); ResultSet rset = statement.executeQuery(); result = rset.next(); rset.close(); statement.close(); } catch (SQLException e) { _log.warn("could not check existing petname:" + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } return result; }
From source file:RSMetaData.java
public static void processRs(ResultSet rs) throws SQLException { ResultSetMetaData rmd = rs.getMetaData(); while (rs.next()) { for (int col = 1; col <= rmd.getColumnCount(); col++) getData(rs, rmd.getColumnType(col), col); }//ww w . j a v a2s .co m }