import javax.swing.JFrame;
class FirstGui extends JFrame{

public static void main(String args[])
{

FirstGui gui=new FirstGui();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

gui.setSize(200,200);
gui.setVisible(true);
gui.setTitle(“First GUI”);
}
}

Advertisements

Thin driver is 4 type driver in java which  provides the connectivity between oracle and java.the main advantage is this driver is we can  connect the database to java without creating DSN,

Oracle has a thin client driver, which mean you can connect to a oracle database without the Oracle client installed on your machine.

Thick client would need the Oracle Client, database drivers,etc

First we have to go to in my Oracle 11 installation directory and find the lib folder,the location for me is E:\app\sourav\product\11.2.0\dbhome_1\jdbc\lib,
there is a file called ojdbc6.jar,we need to create a classpath variable and the value f the variable is the location of this jar file.

To do this we have to go to System-Advanced System Settings-Advanced-Environment Variables

There we have to click new in the User variables section which is on the top location

The name of the variable will be classpath

The value will be E:\app\sourav\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar;

Press Ok and exit

Then it’s time to write some code,I did it in two different ways

The first way is

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

 

class Test {

public static void main(String args[]) throws SQLException {

//URL of Oracle database server
String url = “jdbc:oracle:thin:@localhost:1521:sysdba”;

//properties for creating connection to Oracle database
Properties props = new Properties();
props.setProperty(“user”, “scott”);
props.setProperty(“password”, “tiger”);

//creating connection to Oracle database using JDBC
Connection conn = DriverManager.getConnection(url,props);

String sql =”select sysdate as current_day from dual”;

//creating PreparedStatement object to execute query
PreparedStatement preStatement = conn.prepareStatement(sql);

ResultSet result = preStatement.executeQuery();

while(result.next()){
System.out.println(“Current Date from Oracle : ” + result.getString(“current_day”));
}
System.out.println(“done”);

}
}

The second way is

import java.sql.*;
class databaseconnection{
public static void main(String args[])throws Exception
{
Class.forName(“oracle.jdbc.driver.OracleDriver”);
String url=”jdbc:oracle:thin:@localhost:1521:sysdba”;

 

String username=”scott”;
String password=”tiger”;
Connection con=DriverManager.getConnection(url,username,password);
if(con!=null)
System.out.println(“Connection Established”);
con.close();
}
}

 

 

 

 

 

 

 

 

 

 

 

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style

 

style.use(‘fivethirtyeight’)
bridge_readings={‘Distance_mm’:[50012,50015,50009,5024012,50007,50016,50014]}
df=pd.DataFrame(bridge_readings)
##df.plot()
##plt.show()
stats=df.describe()
print stats
print “standard deviation is “,stats.Distance_mm[‘std’]

#to convert the data from enotation to float

pd.options.display.float_format = ‘{:20,.2f}’.format
#to find the rolling standard deviation
df[‘std’]=pd.rolling_std(df[‘Distance_mm’],2)
print df.head()

#using this method we can see where the deviation skyrockets

#so if we want to print the data where the std is lower than the entire std
#using this method we can remove the extremely high valued variance part
df=df[(df[‘std’]<stats.Distance_mm[‘std’])]

print df.head()

#we could also make the standard deviation less than a constant for example 50

df=df[(df[‘std’]<50)]
print df.head()

df[‘Distance_mm’].plot()
plt.show()

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],4)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

 

 

print att.head()
print ‘************************************************************’

 

att.dropna(how=’all’,inplace=True)
print att.head()
print ‘************************************************************’
#there are two kind of filling one is forward fill and another is backward fill
#in case of forward fill suppose row1 has the value of 5 and row2 and row3 is none
#in forward fill row3 will take the value five
#in backward fill the exact opposite will happen

att.fillna(method=’ffill’,inplace=True)
print att.head()
print ‘************************************************************’

att.fillna(method=’bfill’,inplace=True)
print att.head()

#to replace NaN with predetermined values
#to see the results we have to comment out previous filtered data

 

print ‘************************************************************’

att.fillna(value=-99999, inplace=True)
print att.head()

##to fill a percentage of dataframe with predetermined values
##say for example one percent

 

print ‘************************************************************’
percent=0.01
one_pct=int(len(att)*percent)
att.fillna(value=-99999, inplace=True, limit=one_pct)
print att

 

#if we want to find out after replacing a percentage of NaN if there are still NaN in the dataframe

if att.isnull().values.sum() > 1:
print ‘there are more NaN in the dataframe,to be precise more than ‘, int(percent*100) ,’%’

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],4)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

#this is for dropping the entire column which has NaN

#att.dropna(inplace=True)

 

print att.head()

att2=att.dropna()
print att2.head()

#the output will show side by side in att frame many rows has NaN but in att2 those rows were omitted

 

#however if we want to see the columns which have some Nan but also many important data below,so in summary we want to see
#the all the rows

att3=att.dropna(how=’all’)
print att3.head()

 

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],10)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

 

print att.tail()

 

 

I just love python 2.7,it has small footprints,fast,elegant,many resources can be found on python 2.7 online.so many libraries are available for python 2.7 that a lot of serious development can be done without inventing the wheel again and again.

However there are some issues like the statistics module is not available,so if you try

pip install statistics,you will be faced with an error

To overcome this

you need to download the file get-pip.py from this location

https://bootstrap.pypa.io/get-pip.py

Then go to your python 2.7 directory ,for my pc it is in the C folder,I have both python 3.6 and 2.7,however i prefer python 2.7,but when I type python in command prompt the python always shows as python 3.6,that’s why to excuisitely run python 2.7  I need to go to python2.7 folder in C drive

python get-pip.py

The statistics module should be installed this way

you can taste it by import statistics command

Source

https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=94333

https://pip.pypa.io/en/stable/installing/

 

 

 

 

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],10)

#if we use att.head() the moving averages will be shown as Nan
#because moving averages depends on previous values,so it’s
#better to use tail()

 

#print att.tail()

fig, axes=plt.subplots(nrows=2, ncols=1)
att[’50STD’]=pd.rolling_std(att[‘Close’],50)
att[’50STD’].plot(ax=axes[1],label=’50STD’ )
att[‘Close’].plot(ax=axes[0],label=’Price’)
att[’10MA’].plot(ax=axes[0],label=’10MA’)
att[’50MA’].plot(ax=axes[0],label=’50MA’)
plt.legend(loc=4)

plt.show()

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)

print att.head()
print 80*’#’
#to see the statistical measurements such as
#count mean std min 25% 50% 75% max

print att.describe()

#to see the statistical measurements for a particular column such as for example OPEN

describe=att.describe()
print 80*’#’
print describe[‘Open’]

#to see one single statistical measurement such as for example
#standard deviation for a given column
print 80*’#’
print ‘The standdard Deviation of Open Column is {:0.2f}.\n’.format(describe[‘Open’][‘std’])

 

###now if you type something like att[‘Open’] and the column does not exist it
###it will create the column,butif it exists the comn will be modified
###create a column named Open_Original to retain the values of the Open column
##
##att[‘Open_Original’]=att[‘Open’]
##att[‘Open_Modified’]=att[‘Open’]/10
##
##att[‘high-low’]=att[‘High’]-att[‘Low’]
##att[‘Daily_Rise’]=att[‘Close’]>att[‘Open’]
##del att[‘Open’]
##print att.head()
##
###say for example we only wants to print the rows in this dataframe where
###a condition satisfies for example we like to print the rows where
###the day close is greater than day open
##print 80*’#’
##attfilter=att[(att[‘Close’]>att[‘Open_Original’])]
##print attfilter.head()
##
###say for example we only wants to print the rows in this dataframe where
###a condition satisfies for example we like to print the rows where
###the day high is greater than day close and the difference is equal to or greater than 1 dollar
##
##print 80*’#’
##attfilter2=att[((att[‘High’]-att[‘Low’])>1)]
##print attfilter2.head()
##

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)

print att.head()
print 80*’#’
#now if you type something like att[‘Open’] and the column does not exist it
#it will create the column,butif it exists the comn will be modified
#create a column named Open_Original to retain the values of the Open column

att[‘Open_Original’]=att[‘Open’]
att[‘Open_Modified’]=att[‘Open’]/10

att[‘high-low’]=att[‘High’]-att[‘Low’]
att[‘Daily_Rise’]=att[‘Close’]>att[‘Open’]
del att[‘Open’]
print att.head()

#say for example we only wants to print the rows in this dataframe where
#a condition satisfies for example we like to print the rows where
#the day close is greater than day open
print 80*’#’
attfilter=att[(att[‘Close’]>att[‘Open_Original’])]
print attfilter.head()

#say for example we only wants to print the rows in this dataframe where
#a condition satisfies for example we like to print the rows where
#the day high is greater than day close and the difference is equal to or greater than 1 dollar

print 80*’#’
attfilter2=att[((att[‘High’]-att[‘Low’])>1)]
print attfilter2.head()

Older Posts »

Categories

%d bloggers like this: