List of usage examples for java.sql Connection createStatement
Statement createStatement() throws SQLException;
Statement
object for sending SQL statements to the database. 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,myURL CHAR);"); st.executeUpdate("create view surveyview as (select * from survey);"); getTables(conn);//from w w w .jav a 2 s .com st.close(); conn.close(); }
From source file:DataInserter.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); DriverManager.registerDriver(new JdbcOdbcDriver()); String SQLCommand = "INSERT INTO CONTACT_INFO " + "(First_Name,MI,Last_Name,Street,City,State,Zip) " + "VALUES " + "('Michael','J','Corleone','86 Horsehead Blvd','NY','NY','12345');"; String url = "jdbc:odbc:Contacts"; Connection con = DriverManager.getConnection(url); Statement stmt = con.createStatement(); stmt.execute(SQLCommand);//from w ww.ja va 2 s . co m con.close(); }
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, b CLOB);"); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)"); File file = new File("c:/Java_Dev/data.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setAsciiStream(1, fis, (int) file.length()); pstmt.execute();//from w w w . j a v a 2 s.c o m fis.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(); st.executeUpdate("create table survey (Id int, b BLOB);"); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)"); File file = new File("blob.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setBinaryStream(1, fis, (int) file.length()); pstmt.execute();/* w w w. j a v a 2s . co m*/ fis.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(); st.executeUpdate("create table survey (id int,myURL CHAR);"); getTables(conn);/*from w ww . jav a2s. c o m*/ st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); // st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();/*from w w w . j av a 2s.c o m*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); st.close(); conn.close(); }
From source file:DataUpdater.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); DriverManager.registerDriver(new JdbcOdbcDriver()); String url = "jdbc:odbc:Contacts"; Connection con = DriverManager.getConnection(url); Statement stmt = con.createStatement(); String SQLCommand = "UPDATE CONTACT_INFO " + "SET STREET = '58 Broadway', ZIP = '10008' " + "WHERE First_Name = 'Michael' AND " + "Last_Name ='Corleone';"; stmt.execute(SQLCommand);//from w ww. j av a2s .co m con.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();//from w ww. j av a 2 s. co m ResultSet rs = st.executeQuery("SELECT * FROM survey"); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); Statement st = conn.createStatement(); // st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();//w ww. j ava2 s . co m ResultSet rs = st.executeQuery("SELECT * FROM survey"); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); st.close(); conn.close(); }
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 int, name BINARY );"); String sql = "INSERT INTO survey (name) VALUES(?)"; PreparedStatement pstmt = conn.prepareStatement(sql); String myData = "some string data ..."; byte[] binaryData = myData.getBytes(); pstmt.setBytes(1, binaryData);//from w w w .j av a2 s.c o m pstmt.executeUpdate(); ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); while (rs.next()) { System.out.print(rs.getBytes("name").length + " "); } rs.close(); stmt.close(); conn.close(); }