Hereby is a set of alternative statements how to connect & write info to MySQL database:
import com.mysql.jdbc.jdbc2.optional.*;
@RequiresFullAccess
@Library("C:\\MySQL\\Connector J 5.1.23\\mysql-connector-java-5.1.23-bin.jar")
OnStart block - opens connection..
try {
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName("localhost");
ds.setPortNumber(3306);
ds.setDatabaseName("myticks");
ds.setUser("root");
ds.setPassword("*****");
con = ds.getConnection();
} catch (Exception e) { console.getErr().println(e); }
OnTick / OnBar methods writes info to database..
try {
PreparedStatement ps = con.prepareStatement("INSERT INTO dom (Instrument, Dttm, BidQuote, AskQuote) VALUES (?,?,?,?)");
try {
ps.setString(1, myInst.toString());
ps.setTimestamp(2, new Timestamp(timeStamp), gmtCalendar);
ps.setDouble(3, myTick.getBid());
ps.setDouble(4, myTick.getAsk());
ps.executeUpdate();
} finally { ps.close(); }
} catch (Exception e) { console.getErr().println(e); }
Hope it helps!
Tipota