1、安装mysql驱动程序包
mysql-connector-java-5.1.46-bin.jar下载链接
①:将mysql-connector-java-5.1.7-bin.jar文件拷贝到…\MATLAB\R2009a\java\jar\toolbox
②:到…\MATLAB\R2009a\toolbox\local目录下,找到classpath.txt文件,打开,并添加用来加载mysql的jdbc驱动语句:
$matlabroot/java/jar/toolbox/mysql-connector-java-5.1.7-bin.jar
③:重新打开MATLAB即可
2、操作数据库
conn = database('program','root','root','com.mysql.jdbc.Driver','jdbc:mysql://127.0.0.1:3306/program');
sql = strcat('select id,monitor from db_analysis where result = 0 limit 1');
aTemp = exec(conn,sql);
b = fetch(aTemp);
c = b.Data{1};
if ischar(c) > 0
%%若取不到数据,则退出
return ;
else
%%反演计算
a = get(b,'Data');
id = cell2mat(a(1,1)); %%数据ID
monitor = cell2mat(a(1,2)); %%监测值
load('ceshiweb.mat','net');
norm=35;
input_web=monitor./norm;
an=sim(net,input_web);
output_web=an.*norm;
%%将反演结果存储至数据库
update(conn,'db_analysis',{'result'},{output_web},sprintf('%s%d','where id = ',id));
end