??????????????????????JDBCExample????:??????CentOS release 6.10 (Final) ????8G
??????500w??????????????count??????????????????2000w??????count
????26????????????lotDB??count ????0.01??
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class JDBCExample {
/**
* Before executing a SQL statement with a Statement object, you need to
create a Statement object using the createStatement() method of the Connection
object.
* After creating a Statement object, you can use its execute() method to
execute a SQL statement
* Finally, remember to close the 'statement' and 'connection' objects by
using their close() method
* For statements with query results, we can use the getResultSet() method
of the Statement object to get the result set.
*/
public static void main(String[] args) throws SQLException, ParseException {
Connection connection = getConnection();
if (connection == null) {
System.out.println("get connection defeat");
return;
}
int[] days={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int i=days.length;
while (i-->0){
AddInThread addInThread=new AddInThread(getConnection(),days[i]);
addInThread.start();
}
}
public static Connection getConnection() {
// JDBC driver name and database URL
String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
String url = "jdbc:iotdb://192.168.5.244:6667/";
// Database credentials
String username = "root";
String password = "root";
Connection connection = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
/**
* This is an example of outputting the results in the ResultSet
*/
private static void outputResult(ResultSet resultSet) throws SQLException {
if (resultSet != null) {
System.out.println("--------------------------");
final ResultSetMetaData metaData = resultSet.getMetaData();
final int columnCount = metaData.getColumnCount();
for (int i = 0; i < columnCount; i++) {
System.out.print(metaData.getColumnLabel(i + 1) + " ");
}
System.out.println();
while (resultSet.next()) {
for (int i = 1; ; i++) {
System.out.print(resultSet.getString(i));
if (i < columnCount) {
System.out.print(", ");
} else {
System.out.println();
break;
}
}
}
System.out.println("--------------------------\n");
}
}
}
class AddInThread extends Thread {
final Connection connection;
final int day;
final String datetimeText;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
AddInThread(Connection connection,int days) {
this.connection = connection;
day = days;
datetimeText="2019-11-"+days+" 10:34:59:000";
}
@Override
public void run() {
try {
Date datetime = format.parse(datetimeText);
long times=datetime.getTime();
Statement statement = connection.createStatement();
Integer i = 100;
while (i-- >0) {
statement.execute("insert into
root.ch.baby.d01(timestamp,status) values("+times+++",true)");
}
statement.close();
connection.close();
} catch (ParseException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}