mysql里怎么存word文档,像可以存个链接,可以链接到word文档

mysql里怎么存word文档,像可以存个链接,可以链接到word文档,第1张

mysql表里面搞个longblob字段保存word

代码:

1)上传

try {

ClassforName("commysqljdbcDriver")newInstance();

String url ="jdbc:mysql://localhost/testuser=root&password=root&useUnicode=true&characterEncoding=gbk";

Connection conn = DriverManagergetConnection(url);

Statement stmt = conncreateStatement();

stmtexecute("insert into test(myid) values (5)");

stmtclose();

PreparedStatement pstmt = null;

String sql = "";

File file = new File("c:\\kickjpg");

InputStream photoStream = new FileInputStream(file);

sql = " UPDATE test SET photo = WHERE myid = 5" ;

pstmt = connprepareStatement(sql);

pstmtsetBinaryStream(1, photoStream, (int)filelength());

pstmtexecuteUpdate();

pstmtclose();

connclose();

} catch (Exception e) {

eprintStackTrace();

}

2)下载:

PreparedStatement pst = //省略获取Connection及查询的sql

ResultSet rs = pstexecuteQuery();

InputStream is = rsgetBinaryStream(1); //1表示你的word字段在结果集中的索引号

FileOutputStream fos = new FileOutputStream("path");

byte [] buf = new byte[1024];

while(isread(buf)!=-1){

foswrite(buf);

}

//close省略

大概思路,自己完善

下载一个mysql-front51 可视化工具 然后打开之后 选择你要导入的表。。

右键表名称 选择打开 然后再选择你要导入的word文件 然后下一步 选择word数据里哪一列对应哪个字段 然后一直下一步到最后 word文件里最好有表格

如果不好使 你就把你的word文件里的内容全都复制到excel里面。单元格要处理好哦

大量导入数据库 这个方法很快很快的。

题主是否想询问“python读取word文档导不入mysql数据库怎么办吗”具体如下:

1、用python先把doc文件转换成docx文件

2、然后读取docx的文件并另存为htm格式的文件

3、python根据bs4获取p标签里的内容,如果段落中有则保存。

同步数据库自动化脚本

#!/bin/sh

read -p "Please keyin your ssh host:" -t 30 host_ipread -p "Please keyin your ssh user:" -t 30 usernameread -p "Please keyin your ssh pass:" -t 30 passwordread -p "Please keyin your sync table list,separated by spaces:" -t 30 table_listdatetime=`date +%Y%m%d%H%M%S`

src_file="/tmp/data_$datetimesql"

tar_file="/tmp/data_$datetimetargz"

mysqldump -h127001 -uroot -ppass database_name $table_list > $src_filetar czvf $tar_file $src_file

/expect_scpsh $host_ip $username $password $tar_fileexpect_scpsh代码

#!/tools/bin/expect

set timeout 10

set host [lindex $argv 0]

set username [lindex $argv 1]

set password [lindex $argv 2]

set src_file [lindex $argv 3]

#set dest_file [lindex $argv 4]

spawn scp $src_file $username@$host:/home/$usernameexpect {

"(yes/no)"

{

send "yes\n"

expect "assword:" { send "$password\n"}

}

"assword:"

{

send "$password\n"

}

}

expect "100%"

expect eof

对于msSQL,小格式文件可以转为二进制当成文本存储

但word一般都不小,所以一般情况下都直接保存文件,然后在数据库中保存地址对文件的 *** 作由程序进行

即使oracle这一类有大文件类型的,其实也是通过流来存储文件,常用于图像文件,很少于用office类型的

同步数据库自动化脚本

#!/bin/sh

read -p "Please keyin your ssh host:" -t 30 host_ipread -p "Please keyin your ssh user:" -t 30 usernameread -p "Please keyin your ssh pass:" -t 30 passwordread -p "Please keyin your sync table list,separated by spaces:" -t 30 table_listdatetime=`date +%Y%m%d%H%M%S`

src_file="/tmp/data_$datetimesql"

tar_file="/tmp/data_$datetimetargz"

mysqldump -h127001 -uroot -ppass database_name $table_list > $src_filetar czvf $tar_file $src_file

/expect_scpsh $host_ip $username $password $tar_fileexpect_scpsh代码

#!/tools/bin/expect

set timeout 10

set host [lindex $argv 0]

set username [lindex $argv 1]

set password [lindex $argv 2]

set src_file [lindex $argv 3]

#set dest_file [lindex $argv 4]

spawn scp $src_file $username@$host:/home/$usernameexpect {

"(yes/no)"

{

send "yes\n"

expect "assword:" { send "$password\n"}

}

"assword:"

{

send "$password\n"

}

}

expect "100%"

expect eof

看你需要用什么方式导出,如果是直连数据库,可以使用数据库管理工具导出,如楼下那位兄台的navicat,也可以用mysql官方的管理工具workbench

打开导出界面后,下一步,选择csv格式,导出后excel就能打开了

如果你需要在程序代码中导出,需要找到对应代码的excel处理库。

如php 的 phpExcel( 最新版已更名为 phpoffice/phpspreadsheet) 要根据你当前服务器的php版本选择。

然后根据excel库的api编写代码导出

以上就是关于mysql里怎么存word文档,像可以存个链接,可以链接到word文档全部的内容,包括:mysql里怎么存word文档,像可以存个链接,可以链接到word文档、如何将word导入MYSQL、python读取word文档导不入mysql数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9876603.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存