易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

MySql创建函数

首先需要查看一下创建函数的功能是否开启:
X:\proper\mysql\bin>mysql -h localhost -u root -p
Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.0.22-community-nt-log
Type 'help;' or '\h' for help. Type ' ......

MySQL中增加新用户并对其赋予相应权限的办法

(1)格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
 
(2)例1、增加一个用户user_1密码为123,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MySQL,然后键入以下命令:
mysql> grant select,insert,update,delete on *.* to use ......

Mysql Replication实现mysql主从库自动同步安装指南

http://blog.csdn.net/zhangwenzhe/archive/2008/05/22/2470529.aspx

MySQL 3.23.15
版本之后
,MySQL
提供了数据库复制的功能
,
可以实现两个数据库实时同步
,
增强了
MySQL
数据库的稳定性,而且可以在企业级应用的数据库层实现
Cluster
,不仅大大提高了
mysql
的安全性,同时还减轻了
DBA
大量的工� ......

其他数据库模拟实现mysql的limit语法

假如我有个user表,我想查询符合某些条件的第50个用户开始的10个用户,且不能使用id号between and那样查询,应该怎么写SQL语句?
  在mysql数据库中有limit,offset语句可以方便的实现,那么在SQL server中呢?SQL Server是否支持limit和offset语句呢?
select top 10 * from
(select top 60 * from [user] order by userid) a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号