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 { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String URL = "jdbc:odbc:dbName"; Connection conn = DriverManager.getConnection(URL, "user", "passw"); DatabaseMetaData dmd = conn.getMetaData(); ResultSet rs1 = dmd.getSchemas(); while (rs1.next()) { String ss = rs1.getString(1); ResultSet rs2 = dmd.getTables(null, ss, "%", null); while (rs2.next()) System.out.println(rs2.getString(3) + " " + rs2.getString(4)); }/*from w ww . j av a 2s . c o m*/ conn.close(); }
From source file:PreparedStmt.java
public static void main(String args[]) throws Exception { String query = "SELECT * FROM Stock WHERE Item_Number = ?"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory"); PreparedStatement pstmt = con.prepareStatement(query); pstmt.setInt(1, 2);/*from ww w. j a v a 2 s .c o m*/ ResultSet rs = pstmt.executeQuery(); while (rs.next()) { String name = rs.getString("Name"); String desc = rs.getString("Description"); int qty = rs.getInt("Qty"); float cost = rs.getFloat("Cost"); System.out.println(name + ", " + desc + "\t: " + qty + "\t@ $" + cost); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { int records = 0; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); String sql = "SELECT COUNT(*) FROM mytable"; PreparedStatement prest = con.prepareStatement(sql); ResultSet rs = prest.executeQuery(); while (rs.next()) { records = rs.getInt(1);/*w w w . j av a 2s. com*/ } System.out.println("Number of records: " + records); con.close(); }
From source file:PrintResultSet.java
public static void main(String args[]) throws Exception { String query = "SELECT Name,Description,Qty,Cost FROM Stock"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { System.out.print(rs.getString("Name") + "\t"); System.out.print(rs.getString("Description") + "\t"); System.out.print(rs.getInt("Qty") + "\t"); System.out.println(rs.getFloat("Cost")); }/*w w w . ja v a2 s. c om*/ }
From source file:JdbcDemo.java
public static void main(String args[]) throws Exception { String query = "SELECT Name,Description,Qty,Cost FROM Stock"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String name = rs.getString("Name"); String desc = rs.getString("Description"); int qty = rs.getInt("Qty"); float cost = rs.getFloat("Cost"); System.out.println(name + ", " + desc + "\t: " + qty + "\t@ $" + cost); }// www.j ava 2s . co m con.close(); }
From source file:CallableStmt.java
public static void main(String args[]) throws Exception { String storedProc = "create procedure SHOW_ORDERS_BY_STATE @State CHAR (2) as " + "select c.Last_Name+', '+c.First_Name AS Name,o.Order_Number " + "from CUSTOMERS c, ORDERS o where c.Customer_Number = o.Customer_Number " + "AND c.State = @State order by c.Last_Name;"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Customers"); Statement stmt = con.createStatement(); stmt.executeUpdate(storedProc);/*from ww w . j a v a2s .com*/ CallableStatement cs = con.prepareCall("{call SHOW_ORDERS_BY_STATE(?)}"); cs.setString(1, "NJ"); ResultSet rs = cs.executeQuery(); while (rs.next()) { String name = rs.getString("Name"); int orderNo = rs.getInt("Order_Number"); System.out.println(name + ": " + orderNo); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); ResultSet schemas = meta.getSchemas(); while (schemas.next()) { String tableSchema = schemas.getString(1); // "TABLE_SCHEM" System.out.println("tableSchema:" + tableSchema); String tableCatalog = schemas.getString(2); //"TABLE_CATALOG" System.out.println("tableCatalog:" + tableCatalog); }/*from www .ja v a2 s.co m*/ conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://MYSERVER;databaseName=MYDATABASE", "USERID", "PASSWORD"); CallableStatement proc_stmt = con.prepareCall("{ call generateID(?) }"); proc_stmt.setString(1, "employee"); ResultSet rs = proc_stmt.executeQuery(); if (rs.next()) { int employeeId = rs.getInt(1); System.out.println("Generated employeeId: " + employeeId); } else {/*from w w w . j a v a2 s.co m*/ System.out.println("Stored procedure couldn't generate new Id"); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection c = null;/*from w ww.j av a2 s .com*/ DatabaseMetaData dbm = c.getMetaData(); ResultSet rs = dbm.getTables(null, null, "employee", null); if (rs.next()) { System.out.println("Table exists"); } else { System.out.println("Table does not exist"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); ResultSet catalogs = meta.getCatalogs(); while (catalogs.next()) { String catalog = catalogs.getString(1); //"TABLE_CATALOG" System.out.println("catalog: " + catalog); }/*from w w w .j av a 2s . co m*/ conn.close(); }