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
Ïà¹ØÎĵµ£º
ÔËÐгÌÐò¿ÉÄܻᱨ´í£ºCan’t connect to local MySQL Server through socket ‘/tmp/mysql.sock’
Õâ¸ö´íÎóµÄÌáʾÊÇ˵£¬²»ÄÜͨ¹ý’/tmp/mysql.sock’Á¬½Óµ½·þÎñÆ÷¡£Mysql.sockÊÇ´´½¨Óëmysqld·þÎñÆ÷Ïà¹ØµÄMySQLͨÐŶ˵ãËùʹÓõÄÌ×½Ó×Ö¡£¶øPHP±ê×¼ÅäÖÃÕýÊÇͨ¹ý’/tmp/mysql.sock’À´Á¬½Ó ......
ÀýÈ磬MySQLĬÈϵÄÊý¾ÝÎļþ´æ´¢Ä¿Â¼Îª/var/lib/mysql¡£¼ÙÈçÒª°ÑĿ¼ÒƵ½/home/dataÏÂÐèÒª½øÐÐÏÂÃ漸²½£º
1¡¢homeĿ¼Ï½¨Á¢dataĿ¼
cd /home
mkdir data
2¡¢°ÑMySQL·þÎñ½ø³ÌÍ£µô£º
......
½ñÌìºÍһλ¼Ü¹¹Ê¦ÁÄÁËһЩÎÊÌ⣬ºÜżȻµÄ˵³öÁËÒ»¸öÊÂÇ飬ÎұȽϸÐÐËȤÓÚÊǼǼһÏ£º
1£ºÎÒÃǶ¼ÖªµÀmysqlÏ µÄINNODBºÍMYISAMÁ½ÖÖÒýÇ棬ÆäÖÐINNODB¾ßÓÐÊÂÎï¹ÜÀí¡£ËùÒÔINNODBϲÙ×÷ºÍMYISAMϲÙ×÷£¬µ¥´¿µÄ´Ó²åÈëÊý¾Ý¿âÉÏ˵£¬INNDODBµÄ¿É¿¿£¬²éѯÉÏ˵MYISAMµÄÒª¿ì¡£
2£º»ùÓÚÉÏÃæµÄÌØÐÔ£¬ÒÔ¼°MYSQLjuyouµÄÖ÷´Ó»úÖÆ£¬ÎÒÃÇ¿ÉÒ ......
http://www.ej38.com/showinfo/mysql-130795.html
CentOSÏÂMysqlʵÏÖÊý¾Ý¿âÖ÷´Óͬ²½
Ò»¡¢»·¾³
¡¡¡¡A·þÎñÆ÷£º 192.168.10.42 Ö÷·þÎñÆ÷master¡¡¡¡CentOS 5¡¡¡¡Mysql 5.1.34
¡¡¡¡B·þÎñÆ÷£º 192.168.10.68 ¸±·þÎñÆ÷slave¡¡¡¡¡¡CentOS 5¡¡¡¡Mysql 5.0.56
¶þ¡¢ÉèÖÃMas ......
¼ÙÈçÎÒÓиöuser±í,ÎÒÏë²éѯ·ûºÏijЩÌõ¼þµÄµÚ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 ......