List of usage examples for java.sql ResultSet getString
String getString(String columnLabel) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); String sql = "SELECT name, description, image FROM pictures "; PreparedStatement stmt = conn.prepareStatement(sql); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { String name = resultSet.getString(1); String description = resultSet.getString(2); File image = new File("D:\\java.gif"); FileOutputStream fos = new FileOutputStream(image); byte[] buffer = new byte[1]; InputStream is = resultSet.getBinaryStream(3); while (is.read(buffer) > 0) { fos.write(buffer);//from ww w . j a v a 2s . c om } fos.close(); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.setProperty("oracle.net.tns_admin", "C:/app/product/11.2.0/client_1/NETWORK/ADMIN"); String dbURL = "jdbc:oracle:thin:@ENTRY_FROM_TNSNAMES"; Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection(dbURL, "your_user_name", "your_password"); System.out.println("Connection established"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT dummy FROM dual"); if (rs.next()) { System.out.println(rs.getString(1)); }/*from ww w. j a va2 s. co m*/ stmt.close(); conn.close(); }
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 = conn.createStatement();/*from ww w . ja va2 s.com*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { String name = rs.getString(2); System.out.println(name); } rs.close(); st.close(); conn.close(); }
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 = conn.createStatement();/* w w w .j av a 2 s . c o m*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { String name = rs.getString("name"); System.out.println(name); } rs.close(); st.close(); conn.close(); }
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();//from w ww . j a va 2s .co m ResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { String name = rs.getString("name"); System.out.println(name); } rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Statement stmt = DriverManager.getConnection("jdbc:odbc:employee").createStatement(); ResultSet rs = stmt.executeQuery("select lastname, firstname, id from [Sheet1$]"); while (rs.next()) { String lname = rs.getString(1); String fname = rs.getString(2); int id = rs.getInt(3); System.out.println(fname + " " + lname + " id : " + id); }/*from w w w .j a va 2s. c om*/ rs.close(); stmt.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection dbConnection = null; PreparedStatement preparedStatement = null; Class.forName(DB_DRIVER);// w ww.ja v a2 s . c o m dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); String selectSQL = "SELECT USER_ID, USERNAME FROM Person WHERE USER_ID = ?"; preparedStatement = dbConnection.prepareStatement(selectSQL); preparedStatement.setInt(1, 1001); ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { String userid = rs.getString("USER_ID"); String username = rs.getString("USERNAME"); System.out.println("userid : " + userid); System.out.println("username : " + username); } preparedStatement.close(); dbConnection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection con = null;/* w w w. j a va 2s . 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(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager .getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/access.mdb"); ResultSet rs = c.createStatement().executeQuery("select objet from Employee"); while (rs.next()) { System.out.println(rs.getString("objet")); }//from w w w. j av a 2 s .c om rs.close(); c.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);/*from w w w . j ava2 s .c om*/ pstmt.setBoolean(2, ac); pstmt.setString(3, log); pstmt.setString(4, pass); pstmt.executeUpdate(); } con.close(); con1.close(); }