Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.*;
- public class DatabaseManagement
- {
- Connection con;
- Statement statement; //used for sending commands to DB
- ResultSet rs; //for results from database
- /**
- * constructor opens up the database
- */
- public DatabaseManagement()
- {
- try
- {
- String dataSourceName = "AccessDB";
- String dbURL = "jdbc:odbc:" + dataSourceName;
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- // set this to a MS Access DB you have on your machine
- String filename = "C:/Database/StockData.accdb";
- String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
- database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
- // now we can get the connection from the DriverManager
- con = DriverManager.getConnection( dbURL ,"","");
- /*
- statement = con.createStatement();
- create();
- */
- }
- catch (Exception e)
- {
- System.out.println("Error: " + e);
- }
- }
- //creates the table Stocks in the database if its never been created before
- public void create()
- {
- try
- {
- statement.execute("create table Stocks(ticker_symbol text,stock_date date,open_price double,high_price double,low_price double,close_price double,volume long)");
- }
- catch(SQLException e){}
- }
Add Comment
Please, Sign In to add comment