Here you can find the source of putData(int tID, String toolID)
public static void putData(int tID, String toolID)
//package com.java2s; /*//from w ww. ja va 2s . c om * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; public class Main { private static final String addDataQ = "INSERT INTO `toolsdb`.`customer` (`tenantID`, `toolID`, `time`) VALUES (?, ?, ?)"; private static String dbUrl = "jdbc:mysql://localhost:3306/toolsdb"; private static String user = "root"; private static String password = "root"; public static void putData(int tID, String toolID) { Connection con = null; PreparedStatement preparedStatement = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(dbUrl, user, password); preparedStatement = con.prepareStatement(addDataQ); preparedStatement.setInt(1, tID); preparedStatement.setString(2, toolID); preparedStatement.setTimestamp(3, new Timestamp(System.currentTimeMillis())); preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { try { if (preparedStatement != null) { preparedStatement.close(); } if (con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } } }