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:com.javacreed.examples.sql.Example1.java
public static void main(final String[] args) throws Exception { try (BasicDataSource dataSource = DatabaseUtils.createDataSource(); Connection connection = dataSource.getConnection()) { final ExampleTest test = new ExampleTest(connection, "large_text_table", "text") { @Override// w w w .jav a 2 s. co m protected String parseRow(final ResultSet resultSet) throws Exception { return resultSet.getString("text"); } @Override protected void setPreparedStatement(final String data, final PreparedStatement statement) throws SQLException { statement.setString(1, data); } }; test.runTest(); } Example1.LOGGER.debug("Done"); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection con = null;/*from w w w . java2 s.co 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[] 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 ww .ja v a 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[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { String typeName = rs.getString("TYPE_NAME"); short dataType = rs.getShort("DATA_TYPE"); String createParams = rs.getString("CREATE_PARAMS"); int nullable = rs.getInt("NULLABLE"); boolean caseSensitive = rs.getBoolean("CASE_SENSITIVE"); System.out.println("DBMS type " + typeName + ":"); System.out.println(" java.sql.Types: " + dataType); System.out.print(" parameters used to create: "); System.out.println(createParams); System.out.println(" nullable?: " + nullable); System.out.print(" case sensitive?: "); System.out.println(caseSensitive); System.out.println(""); }//from ww w. j a v a 2 s.c o m conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn = null;/* w w w.j a v a 2 s .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);/* www.java 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()) { 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(url, username, password); PreparedStatement stmt = conn.prepareStatement("SELECT name, description, data FROM documents "); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { String name = resultSet.getString(1); String description = resultSet.getString(2); File data = new File("C:\\a.txt"); Reader reader = resultSet.getCharacterStream(3); FileWriter writer = new FileWriter(data); char[] buffer = new char[1]; while (reader.read(buffer) > 0) { writer.write(buffer);//from www . j a va 2 s . c o m } writer.close(); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); ResultSet r = md.getColumns("", "", "yourTableName", "%"); while (r.next()) System.out.println("\t" + r.getString(4) + " : " + r.getString(6)); conn.close();/*from w w w . j a va 2s . com*/ }
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); DatabaseMetaData metadata = conn.getMetaData(); ResultSet result = metadata.getProcedures(null, "JAVA", "%"); while (result.next()) { System.out.println(result.getString("PROCEDURE_CAT") + " - " + result.getString("PROCEDURE_SCHEM") + " - " + result.getString("PROCEDURE_NAME")); }//from w w w . j av a 2 s . com }
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")); }// w w w. j av a 2s .co m }