String leadsql= "BULK INSERT hnunicom..test1 FROM ";
leadsql += " ' "+fujianWenjian+ " ' ";
leadsql += " with(DATAFILETYPE= 'char ',FIELDTERMINATOR= '| ',ROWTERMINATOR= '\n ') ";
在本机导入是没有问题的。但是在客户端导入的时候,就不可以了。
请教解决办法!
难道非要按行读取文本文件,一行一行往数据库里面写?请高手执教,谢谢
------解决方案--------------------
只要不超过字段的字符数,注意一下 ' ,可以的```
------解决方案--------------------
你要先上传在导入啊
------解决方案--------------------
我写过往mysql里写excel,基本的思路是用一个list跟map,map遍历行,效验通过后写入list,然后将list对象写入数据库具体代码如下:
package cn.com.hitb;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class excel001 {
/**
* 关于配置文件读取的变量声明区
*/
public final static String file = "e:\\test.properties ";
static String driver;
static String url;
static String user;
static String pwd;
static String excel;
static String sql;
/**
* 数据库连接时需用的变量定义
*
*/
static Connection conn = null;
static Statement stmt = null;
/**
* 程序入口
*/
public static void main(String[] args) {
try {
getms();
readXls(excel);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取配置文件信息
*
*/
static void getms() {
try {
Properties p = new Properties();
FileInputStream fs = new FileInputStream(file);
p.load(fs);
driver = p.getProperty( "db.driver ");// 读取驱动信息
url = p.getProperty( "db.url ");// 读取url信息
user = p.getProperty( "db.user ");// 读取用户名
pwd = p.getProperty( "db.pwd ");// 读取密码
excel = p.getProperty( "file.excel ");// 读取文件路径
sql = p.getProperty( "db.sql ");// 读取sql语句
} catch (Exception e) {
System.out.println( "读取配置文件出错~! " + e.getMessage());
}
}
/**
* 读取excel
*
* @param readFileName
* @throws BiffException
* @throws IOException
*/
public static void readXls(String readFileName) throws BiffException,
IOException {
Workbook book = Workbook.getWorkbook(new File(readFileName));
Sheet rs = book.getSheet(0);
int rsRows = rs.getRows();
System.out.println( "excel表有 " + rsRows + "行 ");// 获取一个表有几行
int rsColumns = rs.getColumns();// 获取一个表的总列数(分析与数据库中列数是否一致,不一致则不予更新)
System.out.println( "此表有 " + rsColumns + "列 ");
List rows = new ArrayList();
for (int i = 0; i < rsRows; i++) {
Map map = new HashMap();
map.clear();
for (int j = 0; j < rsColumns; j++) {
map.put(new Integer(j), rs.getCell(j, i).getContents());