Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Demo1 {
- private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
- private static final String DB_CONNECTION ="jdbc:mysql://localhost:3306/db?autoReconnect=true";
- private static final String DB_USER = "root";
- private static final String DB_PASSWORD = "root";
- private static void insertRecord() throws SQLException {
- try{
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- PreparedStatement ps = dbConnection.prepareStatement("SELECT * FROM CMD2");
- //String device_id;
- // TODO Auto-generated method stub
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- Date date = new Date();
- // List<CMD1> arrObj = liveInfo.getTodayFrames(device_id, df.format(date));
- df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- double S ;
- double SH ;
- Date previousDate = null,
- currentTime = null;
- if (previousDate != null) {
- float timeDiff = 2;
- double S1;
- S1 =(Float.parseFloat(cmd.getA())*(cmd.getB()))/1000;
- S = S + S1;
- double SH1;
- S1 =(Float.parseFloat(cmd.getA())* timeDiff )/60;
- SH = SH + SH1;
- previousDate = df.parse(cmd.getDate() + " " + cmd.getTime());
- } else {
- previousDate = df.parse(cmd.getDate() + " " + cmd.getTime());
- S =0 ;
- SH = 0;
- }
- System.out.println(S+" "+SH+" ");
- // PreparedStatement ps1 = dbConnection.prepareStatement("INSERT INTO cmd2( date, time) VALUES(?, ?) FROM CMD");
- ps.setString(1, S);
- ps.setString(3, SH);
- ps.execute();
- System.out.println("Record is inserted into table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally{
- }
- }
- private static Connection getDBConnection() {
- Connection dbConnection = null;
- try {
- Class.forName(DB_DRIVER);
- } catch (ClassNotFoundException e) {
- System.out.println(e.getMessage());
- }
- try {
- dbConnection = DriverManager.getConnection(
- DB_CONNECTION, DB_USER,DB_PASSWORD);
- return dbConnection;
- }
- catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- return dbConnection;
- }
- public static void main(String[] argv) {
- try {
- insertRecord();
- }
- catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement