Java examples for JDBC:SQL Statement
Insert into Derby database
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { public static void main(String[] arguments) { String datasource = "jdbc:derby://localhost:1527/sample"; try (Connection conn = DriverManager .getConnection(datasource, "app", "APP")) { Class.forName("org.apache.derby.jdbc.ClientDriver"); PreparedStatement prep2 = conn.prepareStatement("INSERT INTO " + "STOCKS(PRICE, VOLUME) " + "VALUES(?, ?)"); prep2.setString(1, "0"); prep2.setString(2, "1"); prep2.executeUpdate();//from w ww . j av a 2s . co m conn.close(); } catch (SQLException sqe) { System.out.println("SQL Error: " + sqe.getMessage()); } catch (ClassNotFoundException cnfe) { System.out.println(cnfe.getMessage()); } } }