Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class testDB {
- static Connection connection = null;
- public static void main(String[] argv) {
- if (true == connectdb()) {
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- Date date = new Date();
- System.out.println(dateFormat.format(date)); //2014/08/06 15:59:48
- //System.out.println(date); //2014/08/06 15:59:48
- String createTableSyntax = " create table transaction "
- + "("
- + "TID NUMBER,"
- + "AccountNumber number,"
- + "Amount number,"
- + "type number,"
- + "timestamp varchar2(21)"
- + ")";
- Statement statement = null;
- try {
- statement = connection.createStatement();
- for(int i=1; i<=10; i++)
- {
- String syntax = null;
- syntax= "INSERT INTO transaction VALUES (" + (i+100) + ", " + (144416+i) + "," + 5000 +","+ "0"+ ",'"+ dateFormat.format(date) + "' )";
- //syntax = "insert into transaction values (1, 144418, 1000, 0, 'jan1000')";
- statement.execute(syntax);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean connectdb() {
- System.out.println("-------- Oracle JDBC Connection Testing ------");
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your Oracle JDBC Driver?");
- e.printStackTrace();
- //return;
- }
- System.out.println("Oracle JDBC Driver Registered!");
- try {
- connection = DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:XE", "test", "test");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- //return;
- }
- if (connection != null) {
- System.out.println("You made it, take control your database now!");
- return true;
- } else {
- System.out.println("Failed to make connection!");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement