List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:Main.java
public static void main(String[] argv) throws Exception { int count = 0; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); String sql = "SELECT title,year_made FROM product WHERE year_made >= ? AND year_made <= ?"; PreparedStatement prest = con.prepareStatement(sql); prest.setInt(1, 2000);//from www . j a v a2 s . com prest.setInt(2, 2009); ResultSet rs = prest.executeQuery(); while (rs.next()) { String mov_name = rs.getString(1); int mov_year = rs.getInt(2); count++; System.out.println(mov_name + "\t" + "- " + mov_year); } System.out.println("Number of records: " + count); prest.close(); con.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { CallableStatement cs = conn.prepareCall("{call StoreProcedureName}"); ResultSet rs = cs.executeQuery(); while (rs.next()) { System.out.println("Defunct user: " + rs.getString("user")); }//from w w w . j a va 2 s . c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); String sql = "SELECT * FROM product WHERE year_made = ?"; PreparedStatement prest = con.prepareStatement(sql); prest.setInt(1, 2002);/*w ww .j ava 2 s.c o m*/ ResultSet rs1 = prest.executeQuery(); while (rs1.next()) { String mov_name = rs1.getString(1); int mad_year = rs1.getInt(2); System.out.println(mov_name + "\t- " + mad_year); } prest.setInt(1, 2003); ResultSet rs2 = prest.executeQuery(); while (rs2.next()) { String mov_name = rs2.getString(1); int mad_year = rs2.getInt(2); System.out.println(mov_name + "\t- " + mad_year); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Oracle driver registered"); Connection conn = null;//w w w . j av a 2s . com conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orclh", "scott", "tiger"); Statement stmt = conn.createStatement(); ResultSet r = stmt.executeQuery("Select * from emp"); while (r.next()) { String str = r.getString("ename"); System.out.println(str); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection con = null;//from w w w .j av a 2s. c o m Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver"); con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/Keyspace"); String query = "SELECT * FROM column_family where gender=f "; Statement stmt = con.createStatement(); ResultSet result = stmt.executeQuery(query); while (result.next()) { System.out.println(result.getString("user_name")); System.out.println(result.getString("gender")); System.out.println(result.getString("password")); } con.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);//from w ww .ja v a2 s.c om String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dbmd = connection.getMetaData(); ResultSet resultSet = dbmd.getTypeInfo(); while (resultSet.next()) { String typeName = resultSet.getString("TYPE_NAME"); short dataType = resultSet.getShort("DATA_TYPE"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn = null;/* ww w .j a v a2s. 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[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);//from w ww.j a v a 2s. c om String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dbmd = connection.getMetaData(); ResultSet resultSet = dbmd.getTypeInfo(); while (resultSet.next()) { // Get the database-specific type name String typeName = resultSet.getString("TYPE_NAME"); short dataType = resultSet.getShort("DATA_TYPE"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//server.local:1521/prod", "scott", "tiger"); conn.setAutoCommit(false);/*from w w w. j a va 2 s.co m*/ Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select * from employee"); while (rset.next()) { System.out.println(rset.getString(1)); } stmt.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection con = null;/*from w ww . j a v a2 s. c o m*/ PreparedStatement prepstmt = con.prepareStatement("select Name, Addr from Employee where Id = ?"); prepstmt.setString(1, "1"); ResultSet rs; rs = prepstmt.executeQuery(); boolean found = rs.next(); if (found) System.out.println(rs.getString(1)); prepstmt.close(); }