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 { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/* w w w .j a v a 2 s . co m*/ 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"); // Get the java.sql.Types type to which this database-specific type is // mapped short dataType = resultSet.getShort("DATA_TYPE"); getJdbcTypeName(dataType); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id DECIMAL, name BINARY );"); String sql = "INSERT INTO survey (id) VALUES(?)"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setBigDecimal(1, new BigDecimal("1.00000")); // insert the data pstmt.executeUpdate();/*from ww w .j a v a2 s . com*/ ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); while (rs.next()) { System.out.print(rs.getString(1)); } rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/old", "user", "pass"); Connection con1 = DriverManager.getConnection("jdbc:postgresql://localhost:5432/new", "user", "pass"); String sql = "INSERT INTO users(" + "name," + "active," + "login," + "password)" + "VALUES(?,?,?,?)"; Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); PreparedStatement pstmt = con1.prepareStatement(sql); ResultSet rs = statement.executeQuery("SELECT * FROM users"); while (rs.next()) { String nm = rs.getString(2); Boolean ac = rs.getBoolean(3); String log = rs.getString(4); String pass = rs.getString(5); pstmt.setString(1, nm);/* w ww.ja va 2s . co m*/ pstmt.setBoolean(2, ac); pstmt.setString(3, log); pstmt.setString(4, pass); pstmt.executeUpdate(); } con.close(); con1.close(); }
From source file:EmployeeShow.java
public static void main(String[] args) throws Exception { ImageIcon image;/* ww w . j ava 2 s .c o m*/ Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/c:\\employee"); Statement s = con.createStatement(); ResultSet rs = s.executeQuery("select photo from employee where name = 'Duke'"); if (rs.next()) { Blob photo = rs.getBlob(1); ObjectInputStream ois = null; ois = new ObjectInputStream(photo.getBinaryStream()); image = (ImageIcon) ois.readObject(); } s.close(); }
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"); Statement st = con.createStatement(); ResultSet res = st.executeQuery("SELECT col_name FROM mytable ORDER BY col_name ASC"); while (res.next()) { int col = res.getInt(1); System.out.println(col);/*from ww w.j a v a2s .com*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 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,null)"); st.executeUpdate("insert into survey (id,name ) values (3,'Tom')"); st = conn.createStatement();/* ww w . ja v a 2s . com*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { String name = rs.getString(2); if (rs.wasNull()) { System.out.println("was NULL"); } else { System.out.println("not NULL"); } } rs.close(); st.close(); conn.close(); }
From source file:MainClass.java
public static void main(String[] args) { try {/*from ww w . ja v a 2s.com*/ Class.forName("COM.cloudscape.core.JDBCDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:cloudscape:GAMETRADER"); Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT * FROM tableName"); while (rs.next()) { int id = rs.getInt("GAMEID"); Document manual = (Document) rs.getObject("MANUAL"); XMLSerializer serialize = new XMLSerializer(System.out, null); serialize.serialize(manual); } } catch (Throwable e) { System.out.println("exception thrown"); System.out.println(e); } }
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);/*from w w w .j av a2 s. c om*/ pstmt.executeUpdate(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { System.out.print(rs.getDate(2)); } rs.close(); st.close(); conn.close(); }
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"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("DESCRIBE myTable"); ResultSetMetaData md = rs.getMetaData(); int col = md.getColumnCount(); for (int i = 1; i <= col; i++) { String col_name = md.getColumnName(i); System.out.println(col_name); }//from w w w . ja v a 2 s . c o m DatabaseMetaData dbm = con.getMetaData(); ResultSet rs1 = dbm.getColumns(null, "%", "myTable", "%"); while (rs1.next()) { String col_name = rs1.getString("COLUMN_NAME"); String data_type = rs1.getString("TYPE_NAME"); int data_size = rs1.getInt("COLUMN_SIZE"); int nullable = rs1.getInt("NULLABLE"); System.out.println(col_name + " " + data_type + "(" + data_size + ")"); if (nullable == 1) { System.out.println("YES"); } else { System.out.println("NO"); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);// w ww . j ava2 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(); String[] types = { "TABLE" }; ResultSet resultSet = dbmd.getTables(null, null, "%", types); while (resultSet.next()) { String tableName = resultSet.getString(3); String tableCatalog = resultSet.getString(1); String tableSchema = resultSet.getString(2); } }