Excel数据使用jdbc直接插入Mysql数据库
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import jxl.*;
public class ImportExcel {
public static void main(String[] args) {
File importExcel = new File("D:\\test\\test.xls");
try {
// 数据库连接
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/datebaseTest?characterEncoding=UTF-8", "root", "");
PreparedStatement prep = conn
.prepareStatement("insert into importe (id,name) values (?,?)");
Workbook workBook = Workbook.getWorkbook(importExcel);
Sheet[] sheet = workBook.getSheets();
int sheet_i_num = 0;
String id = "";
String name = "";
if (sheet != null && sheet.length > 0) {
for (int sheetNum = 0; sheetNum < sheet.length; sheetNum++) {
sheet_i_num = sheet[sheetNum].getRows();
for (int rowNum = 1; rowNum < sheet_i_num; rowNum++) {
Cell[] cells = sheet[sheetNum].getRow(rowNum);
id = cells[0].getContents();
name = cells[1].getContents();
prep.setInt(1, Integer.parseInt(id));
prep.setString(2, name);
prep.executeUpdate();
System.out.println(id + "--------" + name);
}
}
}
workBook.close();
prep.close();
conn.close();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
}
}
}
在mysql中建立数据表
CREATE TABLE importe (
Id int(11) NOT NULL auto_increment,
name varchar(50) default NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
______________________________________________________________________
向数据库中插入时间,将Excel中时间的格式dd/MM/yyyy插入数据库中,我认为这需要格式转换为yyyy-MM-dd格式。
对于Mysql 建立表格
create table test(
id int(10),
datafrom date);
在Excel中,建立表格,保存为2003的Excel。
Id Data
1 25/11/2009
2 26/11/2009
3 27/11/2009
import java.io.File;
import java.sql.Connec
相关文档:
http://www.3d308.cn/article.asp?id=37
shell> mysql -u root mysql
mysql> Update user SET Password=PASSWORD('new_password')
Where user='root';
mysql> FLUSH PRIVILEGES;
......
项目从mysql迁移到ORACLE中遇到移植问题,mysql中支持limit 而ORACLE say no .
解决方法 利用ORACLE的伪列 rownum来控制。。
Mysql : select * from table limit 10
equl
ORACLE: select * from table where rownum <= 10
ORACLE 伪列介绍:
随数据字典一起自动创建的一个表,属于sys模式,任何用户都可以访问,&nbs ......
MySql版本:mysql-noinstall-5.1.43-win32
系统:Vista
在C:\myProgram Files\mysql-5.1.43-win32(解压的目录)下将选一个配置文件(my-small.ini)编辑:
1.在[client]下添加:
default-character-set=utf8 ......
etting up OpenLDAP with MySQL backend
用mysql作后台数据库安装openldap
author: TBONIUS
OpenLDAP is an X.500 Lightweight Directory Access Server used for
centralized authentication and directory lookups. ......
运行程序可能会报错:Can’t connect to local MySQL Server through socket ‘/tmp/mysql.sock’
这个错误的提示是说,不能通过’/tmp/mysql.sock’连接到服务器。Mysql.sock是创建与mysqld服务器相关的MySQL通信端点所使用的套接字。而PHP标准配置正是通过’/tmp/mysql.sock’来连接 ......