1.读取execl(只能读取.xls的execl,即只能读取03版的),如果是.xlsx类型的话 手工转化一下即可
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* @author 作者:gzh
* @version 创建时间:2015-4-30上午11:26:13
* 类说明:
* 1.读取execl(只能读取.xls的execl,即只能读取03版的),如果是.xlsx类型的话 手工转化一下即可
* 2.应用的jar包是apache的poi系类的jar包和
* 3.ojdbc14.jar的数据库连接包。
**/
public class ExeclOperateMain {
/**
* 方法说明:
* @param args
* @return void
*/
public static void main(String[] args) throws Exception {
ExeclOperateMain e=new ExeclOperateMain();
e.getExcel();
System.out.println("Execl导入完成!");
}
/**
* 用于连接oracle数据库的方法
* 只需修改中的参数getConnection("url","用户名","密码");
*/
public Connection conn(){
try {
//第一步:加载JDBC驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//第二步:创建数据库连接
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.202:1521:orcl", "mdb", "mdb");
return con;
}catch(ClassNotFoundException cnf){
System.out.println("驱动未找到!:"+cnf);
return null;
}catch(SQLException sqle){
System.out.println("不能连接数据库:"+sqle);
return null;
}
catch (Exception e) {
System.out.println("加载失败 JDBC/ODBC driver.");
return null;
}
}
/**
* excel表 的读取
* @throws Exception
*/
public void getExcel() throws Exception {
// 创建对Excel工作簿文件的引用
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("E:\Workspaces\pt-zt-v1.0\src\test.xls"));
// 创建对工作表的引用。
// 在Excel文档中,第一张工作表的缺省索引是0,
// 读取左上端单元
for (int i = 0; i 0){//行,6行
HSSFSheet childSheet = workbook.getSheetAt(i);
for(int rowi=1;rowi<p> </p><p></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e352aa140.jpg" alt="Build MCP servers and clients for PHP applications with the official PHP SDK" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="overflowclass">Build MCP servers and clients for PHP applications with the official PHP SDK</a>
<p class="overflowclass">使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p> </p>