String driver = "com.mysql.jdbc.Driver";
String dburl = "jdbc:mysql://127.0.0.1:3306/dddddd?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull" ;
String username = "root" ;
String password = "root" ;
Connection conn = null;
PreparedStatement ps = null;
String sql = "insert into dd() values(?,?,?,?,?,?,?,?)";
try {
Class.forName(driver); //classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(dburl, username, password);
ps = conn.prepareStatement(sql);
jxl.Workbook readwb = null;
InputStream instream = new FileInputStream("");
readwb = Workbook.getWorkbook(instream);
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(new Date());
// int c = 0;
int c = 215;
for (int i = 0; i < rsRows; i++)
{
String timeCode = "";
Cell cell = readsheet.getCell(1, i);
Cell message = readsheet.getCell(2, i);
String key = cell.getContents();
if(key.equals("")){
timeCode = "0";
}else if(key.equals("")){
timeCode = "1";
}
else if(key.equals("")){
timeCode = "2";
}
if(!key.equals("") && !key.equals("")&&!key.equals("")){
key = "";
timeCode = "";
}
if(!message.getContents().equals("")){
c++;
String no = "";
if(c<10){
no = "m000"+c;
}else if(c<100){
no = "m00"+c;
}else if(c <1000){
no = "m0"+c;
}else if(c < 10000){
no = "m"+c;
}
ps.setString(1, no);
ps.setString(2,timeCode);
ps.setString(3, key);
ps.setString(4, message.getContents());
ps.setString(5, date);
ps.setString(6, "admin");
ps.setString(7, "");
ps.setString(8, "0");
ps.addBatch();
ps.executeBatch();
}
}
String dburl = "jdbc:mysql://127.0.0.1:3306/dddddd?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull" ;
String username = "root" ;
String password = "root" ;
Connection conn = null;
PreparedStatement ps = null;
String sql = "insert into dd() values(?,?,?,?,?,?,?,?)";
try {
Class.forName(driver); //classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(dburl, username, password);
ps = conn.prepareStatement(sql);
jxl.Workbook readwb = null;
InputStream instream = new FileInputStream("");
readwb = Workbook.getWorkbook(instream);
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(new Date());
// int c = 0;
int c = 215;
for (int i = 0; i < rsRows; i++)
{
String timeCode = "";
Cell cell = readsheet.getCell(1, i);
Cell message = readsheet.getCell(2, i);
String key = cell.getContents();
if(key.equals("")){
timeCode = "0";
}else if(key.equals("")){
timeCode = "1";
}
else if(key.equals("")){
timeCode = "2";
}
if(!key.equals("") && !key.equals("")&&!key.equals("")){
key = "";
timeCode = "";
}
if(!message.getContents().equals("")){
c++;
String no = "";
if(c<10){
no = "m000"+c;
}else if(c<100){
no = "m00"+c;
}else if(c <1000){
no = "m0"+c;
}else if(c < 10000){
no = "m"+c;
}
ps.setString(1, no);
ps.setString(2,timeCode);
ps.setString(3, key);
ps.setString(4, message.getContents());
ps.setString(5, date);
ps.setString(6, "admin");
ps.setString(7, "");
ps.setString(8, "0");
ps.addBatch();
ps.executeBatch();
}
}