import java.text.*;
import java.util.Date;
public class Hello {
String dateFormat = "yyyy-MM-dd";
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
public static void main(String[] args) {
Hello t = new Hello();
String date1 = "2018-10-15";
String date2 = "2018-10-21";
t.process(date1, date2);
}
private void process(String date1, String date2){
if(date1.equals(date2)){
System.out.println("两个日期相等!");
return;
}
String tmp;
String sql1 = "";
if(date1.compareTo(date2) > 0){ //确保 date1的日期不晚于date2
tmp = date1; date1 = date2; date2 = tmp;
}
tmp = format.format(str2Date(date1).getTime() + 3600*24*1000);
int num = 0;
while(tmp.compareTo(date2) < 0){
System.out.println(tmp);
sql1 = sql1+" SUM(IF(DATE_FORMAT(createtime,"+ "\"%Y-%m-%d\"" +") =" +
"'"+tmp+"'"+", male+female, 0)) AS " +"'"+tmp+"'"+"," ;
num++;
tmp = format.format(str2Date(tmp).getTime() + 3600*24*1000);
}
//
sql1="SELECT wokstationid, male+female,createtime, " +
sql1+ " createtime " +
" FROM t_b_events WHERE createtime > '2018-10-17' AND createtime < '2019-01-01' AND wokstationid=145";
System.out.println(sql1);
if(num == 0)
System.out.println("两个日期相邻!");
}
private Date str2Date(String str) {
if (str == null) return null;
try {
return format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
id male 2018-10-1 2018-10-2 2018-10-3
1 2 3 1 2
2 1 1 0 8
import java.text.*;import java.util.Date; public class Hello { String dateFormat = "yyyy-MM-dd"; SimpleDateFormat format = new SimpleDateFormat(dateFormat); public static void main(St...
mysql
-connector-
java
.jar包的下载教程:
1.首先我们打开
mysql
的官网:https://www.
mysql
.com/
2.点击选择DOWNLOADS选项:
3.点击选择Community选项:
4.在左侧选项卡中选择
MySQL
Connectors选项:
5.单击选择Connector/J选项:
6.在此处下拉选择Platform Independent 选项:
7.选择下载第二个即可:
8.最后选择No thanks,just start my download:
到此这篇关于
mysql
-connector-
java
.jar包的下载过程详解的文章就介
数据表结构三张表:学生表、课程表、成绩表CREATE TABLE `student` (
`stuid` VARCHAR(16) NOT NULL COMMENT '学号',
`stunm` VARCHAR(20) NOT NULL COMMENT '学生姓名',
PRIMARY KEY (`stuid`)
COLLATE='utf8_general_ci'
ENGIN...
import
java
.
sql
.Connection;
import
java
.
sql
.DriverManager;
import
java
.
sql
.
SQL
Exception;
import
java
.
sql
.Statement;
public class BatchInsertDemo {
public static void main(String[] args) {
String url = "jdbc:
mysql
://localhost:3306/test";
String user = "root";
String password = "123456";
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
conn.setAutoCommit(false);
String
sql
= "INSERT INTO user(name, age) VALUES('Tom', 18)";
stmt.addBatch(
sql
);
sql
= "INSERT INTO user(name, age) VALUES