2019.02.18 08:23 PM
package jforex;import com.dukascopy.api.*;import java.util.*;import java.sql.*;import javax.sql.*;import org.apache.commons.dbcp.*;/** * commons-pool can be downloaded here - http://commons.apache.org/pool/ * commons-dbcp can be downloaded here - http://commons.apache.org/dbcp/ * mysql java connection can be downloaded here - http://dev.mysql.com/downloads/connector/j/5.1.html */@RequiresFullAccess@Library("c:/fullpathtolib/commons-pool-1.4.jar;c:/fullpathtolib/commons-dbcp-1.2.2.jar;c:/fullpathtolib/mysql-connector-java-5.1.7-bin.jar")public class TestMySQLAccess implements IStrategy { private IContext context; private IConsole console; private DataSource dataSource; private Calendar gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); public void onStart(IContext context) throws JFException { this.context = context; console = context.getConsole(); try { Properties properties = new Properties(); properties.put("driverClassName", "com.mysql.jdbc.Driver"); properties.put("url", "jdbc:mysql://localhost/test"); properties.put("username", "test"); properties.put("password", "test"); properties.put("poolPreparedStatements", "true"); dataSource = BasicDataSourceFactory.createDataSource(properties); } catch (Exception e) { console.getErr().println(e); } } public void onAccount(IAccount account) throws JFException { } public void onMessage(IMessage message) throws JFException { } public void onStop() throws JFException { try { ((BasicDataSource) dataSource).close(); } catch (SQLException e) { console.getErr().println(e); } } public void onTick(Instrument instrument, ITick tick) throws JFException { try { Connection connection = dataSource.getConnection(); try { PreparedStatement statement = connection.prepareStatement("insert into ticks(instrument, tick_time, ask, bid, askVol, bidVol) values (?, ?, ?, ?, ?, ?)"); try { statement.setString(1, instrument.toString()); statement.setTimestamp(2, new Timestamp(tick.getTime()), gmtCalendar); statement.setDouble(3, tick.getAsk()); statement.setDouble(4, tick.getBid()); statement.setDouble(5, tick.getAskVolume()); statement.setDouble(6, tick.getBidVolume()); statement.execute(); } finally { statement.close(); } } finally { connection.close(); } } catch (SQLException e) { console.getErr().println(e); } } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }}
I think this code can be easily modified to use a Kdb+ table instead of MySql by a java programmer (that I'm not).Please can you help me?
CheersFrancisco
2019.02.23 10:05 PM
2019.02.27 12:35 AM
2019.03.12 08:56 PM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.