List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet catalogs = null; DatabaseMetaData meta = conn.getMetaData(); catalogs = meta.getCatalogs();//from www. ja va 2 s . c o m while (catalogs.next()) { String catalog = catalogs.getString(1); //"TABLE_CATALOG" System.out.println("catalog: " + catalog); } st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet rs = null; DatabaseMetaData meta = conn.getMetaData(); rs = meta.getTypeInfo();/*from w w w . ja v a2 s. c o m*/ while (rs.next()) { // Get the database-specific type name String typeName = rs.getString("TYPE_NAME"); // Get the java.sql.Types type to which this // database-specific type is mapped short dataType = rs.getShort(2); // Get the name of the java.sql.Types value. System.out.println("type name=" + typeName); System.out.println("dataType=" + dataType); System.out.println("jdbcType=" + dataType); } st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet rs = null; DatabaseMetaData meta = conn.getMetaData(); rs = meta.getTypeInfo();//from w w w.j a v a 2s . c om while (rs.next()) { // Get the database-specific type name String typeName = rs.getString("TYPE_NAME"); // Get the java.sql.Types type to which this // database-specific type is mapped short dataType = rs.getShort("DATA_TYPE"); // Get the name of the java.sql.Types value. System.out.println("type name=" + typeName); System.out.println("dataType=" + dataType); System.out.println("jdbcType=" + dataType); } st.close(); conn.close(); }
From source file:TestDataEncryptionIntegrity.java
public static void main(String[] argv) throws Exception { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Properties prop = new Properties(); prop.setProperty("user", "scott"); prop.setProperty("password", "tiger"); prop.setProperty("oracle.net.encryption_client", "REQUIRED"); prop.setProperty("oracle.net.encryption_types_client", "( RC4_40 )"); prop.setProperty("oracle.net.crypto_checksum_client", "REQUIRED"); prop.setProperty("oracle.net.crypto_checksum_types_client", "( MD5 )"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", prop); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery( "select 'Hello Thin driver Encryption & Integrity " + "tester '||USER||'!' result from dual"); while (rset.next()) System.out.println(rset.getString(1)); rset.close();//from w w w.j a v a 2s . c o m stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String url = "jdbc:odbc:technical_library"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String theStatement = "SELECT authid, lastname, firstname, email FROM authors ORDER BY authid"; try {//from w w w .ja v a2 s. c om Class.forName(driver); Connection connection = DriverManager.getConnection(url, "guest", "guest"); Statement queryAuthors = connection.createStatement(); ResultSet results = queryAuthors.executeQuery(theStatement); String lastname, firstname, email; int id; while (results.next()) { id = results.getInt(1); lastname = results.getString(2); firstname = results.getString(3); email = results.getString(4); if (results.wasNull()) { email = "no email"; } System.out.println(Integer.toString(id) + ", " + lastname.trim() + ", " + firstname.trim() + ", " + email.trim()); } queryAuthors.close(); } catch (Exception e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws SQLException { // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@yourDB", "scott", "tiger"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setFetchSize(1);//from w ww . j a va 2 s . c o m ResultSet rset = stmt.executeQuery("select EMPNO, ENAME, SAL from EMP"); showProperty(rset); while (rset.next()) { System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getInt(3)); } doSomeChanges(conn); // Place the cursor before the first row rset.beforeFirst(); while (rset.next()) { System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getInt(3)); } rset.close(); stmt.close(); cleanup(conn); conn.close(); }
From source file:id.aas.apps.mvc.view.pieChart.java
public static void main(String[] args) throws SQLException { // pieChart p = new pieChart(); // p.setVisible(true); // p.run(); EventQueue.invokeLater(new Runnable() { @Override//from www.j a v a2 s . c om public void run() { try { int nilaiKiloan = 0; int nilaiSatuan = 0; pieChart frame = new pieChart(); frame.setVisible(true); String queryKiloan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Kiloan'"; String querySatuan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Satuan'"; ConnectionDB.InstanceDB.openConnection(); ResultSet rs = ConnectionDB.InstanceDB.RunSelectQuery(queryKiloan); while (rs.next()) { nilaiKiloan = rs.getInt(1); } System.out.println(nilaiKiloan); ResultSet rs1 = ConnectionDB.InstanceDB.RunSelectQuery(querySatuan); while (rs1.next()) { nilaiSatuan = rs1.getInt(1); } System.out.println(nilaiSatuan); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Laundry Kiloan", nilaiKiloan); pieDataset.setValue("Laundry Satuan", nilaiSatuan); JFreeChart chart = ChartFactory.createPieChart3D("Perbandingan Pengguna Layanan Laundry", pieDataset, true, true, false); ChartPanel cPanel = new ChartPanel(chart); frame.setContentPane(cPanel); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:PrimaryKeysSuppliers.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;//from ww w.ja v a 2s . com String createString = "create table SUPPLIERSPK " + "(SUP_ID INTEGER NOT NULL, " + "SUP_NAME VARCHAR(40), " + "STREET VARCHAR(40), " + "CITY VARCHAR(20), " + "STATE CHAR(2), " + "ZIP CHAR(5), " + "primary key(SUP_ID))"; Statement stmt; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(); stmt.executeUpdate(createString); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getPrimaryKeys(null, null, "SUPPLIERSPK"); while (rs.next()) { String name = rs.getString("TABLE_NAME"); String columnName = rs.getString("COLUMN_NAME"); String keySeq = rs.getString("KEY_SEQ"); String pkName = rs.getString("PK_NAME"); System.out.println("table name : " + name); System.out.println("column name: " + columnName); System.out.println("sequence in key: " + keySeq); System.out.println("primary key name: " + pkName); System.out.println(""); } rs.close(); con.close(); } catch (SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String WRITE_OBJECT_SQL = "BEGIN " + " INSERT INTO java_objects(object_id, object_name, object_value) " + " VALUES (?, ?, empty_blob()) " + " RETURN object_value INTO ?; " + "END;"; String READ_OBJECT_SQL = "SELECT object_value FROM java_objects WHERE object_id = ?"; Connection conn = getOracleConnection(); conn.setAutoCommit(false);/* w w w. j a v a2 s . c o m*/ List<Object> list = new ArrayList<Object>(); list.add("This is a short string."); list.add(new Integer(1234)); list.add(new java.util.Date()); // write object to Oracle long id = 0001; String className = list.getClass().getName(); CallableStatement cstmt = conn.prepareCall(WRITE_OBJECT_SQL); cstmt.setLong(1, id); cstmt.setString(2, className); cstmt.registerOutParameter(3, java.sql.Types.BLOB); cstmt.executeUpdate(); BLOB blob = (BLOB) cstmt.getBlob(3); OutputStream os = blob.getBinaryOutputStream(); ObjectOutputStream oop = new ObjectOutputStream(os); oop.writeObject(list); oop.flush(); oop.close(); os.close(); // Read object from oracle PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); InputStream is = rs.getBlob(1).getBinaryStream(); ObjectInputStream oip = new ObjectInputStream(is); Object object = oip.readObject(); className = object.getClass().getName(); oip.close(); is.close(); rs.close(); pstmt.close(); conn.commit(); // de-serialize list a java object from a given objectID List listFromDatabase = (List) object; System.out.println("[After De-Serialization] list=" + listFromDatabase); conn.close(); }
From source file:AutoGenKeys.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con = null;//from w ww . j a v a2 s .co m PreparedStatement pstmt; String insert = "INSERT INTO COFFEES VALUES ('HYPER_BLEND', " + "101, 10.99, 0, 0)"; String update = "UPDATE COFFEES SET PRICE = ? WHERE KEY = ?"; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); pstmt = con.prepareStatement(insert, Statement.RETURN_GENERATED_KEYS); pstmt.executeUpdate(); ResultSet keys = pstmt.getGeneratedKeys(); int count = 0; keys.next(); int key = keys.getInt(1); pstmt = con.prepareStatement(update); pstmt.setFloat(1, 11.99f); pstmt.setInt(2, key); pstmt.executeUpdate(); keys.close(); pstmt.close(); con.close(); } catch (SQLException e) { e.printStackTrace(); } }