紧急~~~用java截取文件中的595.22 842,将其写入到数据库中。我用的insert into table2。。
packagex;importjava.io.*;importjava.sql.Connection;importjava.sql.DriverManager;impor...
package x;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Text{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new FileReader( "c://rf//c.pdf "));
String line="";
while((line = in.readLine())!=null)
while(true) {int index = line.indexOf("MediaBox[");//查找匹配字符串起始位置
if(index < 0) break; //从匹配字符串开始位置截取
line = line.substring(index+12);
index = line.indexOf("]"); //查找匹配字符串结束位置
System.out.println(line.substring(0,index)); //那你把分开来,然后赋值给下面我定义的两个参数里面就好了,
line= line.substring(index+1); }
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=c:/rf/xieru.mdb";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
// String sql1="insert into table2(width, high)VALUES('line.substring(0,index)')"; //添加一行数据到数据库
//String high="line";
// String width="x";
// String sql1=String.format("insert into table2(width, high)VALUES('{0}','{1}'),",high,width);
String sql1="insert into table2(width, high)VALUES('595.22','842')";//这样是可以将数据写入到数据库,但是595.22 842的值时我输入进去的,请高手给我指点下,VALUES('595.22','842')";中的值根据上边截取出来的值而变,自动改变,不需要手动
statement.executeUpdate(sql1);
connection.close();
statement.close();}
catch(Exception ex){
}finally{
}
}
} 展开
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Text{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new FileReader( "c://rf//c.pdf "));
String line="";
while((line = in.readLine())!=null)
while(true) {int index = line.indexOf("MediaBox[");//查找匹配字符串起始位置
if(index < 0) break; //从匹配字符串开始位置截取
line = line.substring(index+12);
index = line.indexOf("]"); //查找匹配字符串结束位置
System.out.println(line.substring(0,index)); //那你把分开来,然后赋值给下面我定义的两个参数里面就好了,
line= line.substring(index+1); }
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=c:/rf/xieru.mdb";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
// String sql1="insert into table2(width, high)VALUES('line.substring(0,index)')"; //添加一行数据到数据库
//String high="line";
// String width="x";
// String sql1=String.format("insert into table2(width, high)VALUES('{0}','{1}'),",high,width);
String sql1="insert into table2(width, high)VALUES('595.22','842')";//这样是可以将数据写入到数据库,但是595.22 842的值时我输入进去的,请高手给我指点下,VALUES('595.22','842')";中的值根据上边截取出来的值而变,自动改变,不需要手动
statement.executeUpdate(sql1);
connection.close();
statement.close();}
catch(Exception ex){
}finally{
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询