DBCrawler 使用
来源:互联网 发布:调货软件 编辑:程序博客网 时间:2024/06/03 16:49
DBCrawler是一个纯java编写的轻量级面向数据库结构的爬虫工具.
最近,DBCrawler发布了其1.4版本,主要支持的数据库包括Apache Derby,H2 Database,HSQLDB,IBM DB2,MySQL,PostgreSQL,同时支持试图操作.其最大的特点就是可以无视数据库类型,轻易获取数据库表结构并以POJO方式返回给用户,使用实例:
1.加入maven库:
在你工程的pom文件中project下一级别加入库:
<repositories>
<repository>
<id>dbcrawler-repo</id>
<name>dbcrawler Maven2 Repository</name>
<url>http://dbcrawler.googlecode.com/svn/repo</url>
</repository>
</repositories>
然后加入依赖:
<!--dbcrawler-->
<dependency>
<groupId>com.avdheshyadav</groupId>
<artifactId>dbcrawler</artifactId>
<version>1.4</version>
</dependency>
2.使用代码
package com.taobao.zhaopin.dal.dao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Set;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.unitils.UnitilsJUnit3;
import org.unitils.spring.annotation.SpringApplicationContext;
import org.unitils.spring.annotation.SpringBean;
import com.avdheshyadav.dbcrawler.ConfigEnum;
import com.avdheshyadav.dbcrawler.DBCrawler;
import com.avdheshyadav.dbcrawler.DbCrawlerException;
import com.avdheshyadav.dbcrawler.dbmodel.ColumnSet;
import com.avdheshyadav.dbcrawler.dbmodel.DataBase;
import com.avdheshyadav.dbcrawler.dbmodel.ForeignKey;
import com.avdheshyadav.dbcrawler.dbmodel.PrimaryKey;
import com.avdheshyadav.dbcrawler.dbmodel.Schema;
import com.avdheshyadav.dbcrawler.dbmodel.SchemaSet;
import com.avdheshyadav.dbcrawler.dbmodel.Table;
import com.avdheshyadav.dbcrawler.dbmodel.TableSet;
@SpringApplicationContext({"classpath:persistence.xml"})
public class DBCrawlerTest extends UnitilsJUnit3{
@SpringBean("sqlMapClientTemplate")
private SqlMapClientTemplate sqlMapClientTemplate;
public void testCrawler() throws DbCrawlerException, SQLException{
Connection connection = sqlMapClientTemplate.getSqlMapClient().getDataSource().getConnection();
DBCrawler dbCrawler = new DBCrawler(connection, ConfigEnum.MAXIMUM);
DataBase dataBase = dbCrawler.getDatabase();
System.out.println("productName :" + dataBase.getProductName() + " version:" + dataBase.getProductVersion());
SchemaSet schemaSet = dataBase.getSchemaSet();
Set<Schema> schemas = schemaSet.getSchemas();
for(Schema schema : schemas)
{
System.out.println("SchemaName :" + schema.getSchamaName());
TableSet tableSet = schema.getTableSet();
Set<Table> tables = tableSet.getTables();
//Iterate to fetch the tables
for(Table table : tables)
{
System.out.println("tableName :" + table.getTableName());
PrimaryKey primaryKey = table.getPrimaryKey();
System.out.println("pk_Name:"+primaryKey.getPkName() + " PrimaryKey Columns:" + primaryKey.getColumns());
ColumnSet columnSet = table.getColumnSet();
System.out.println("Table Columns:"+ columnSet.getColumns());
Set<ForeignKey> foreignKeys = table.getForeignKeys();
System.out.println("foreignKeys:"+foreignKeys);
}
}
}
}
- DBCrawler 使用
- 使用
- 使用
- 使用
- 使用
- 使用
- 使用
- 使用++,--
- 使用$@ $!
- 使用
- SoftICE使用(指令使用)
- 使用GraphEdit使用
- 使用HtmlParser使用心得
- 时钟使用使用
- Ubuntu 使用Git 使用
- Ubuntu 使用Git 使用
- GUID使用的使用
- Git使用 tortoisegit使用
- the language dll 'vbe6int.dll' could not be found
- 安装Mvc2之后无法打开Mvc1程序|安装新的Sp后Vs无法打开老项目
- 如何将以选择好的文本存入剪切板中。
- 谈谈最近Oracle与Google的Java知识产权之争
- linux 客户端 Socket 非阻塞connect编程(源码)
- DBCrawler 使用
- WebPart开发环境搭建
- 《深入解析Oracle》学习笔记(4)--- Oracle中的参数和参数文件
- DOM生成和解析xml
- android上显示空格
- nginx源码分析(1):hash的使用
- Reading binary data in C#
- debug小结
- 如何自动识别判断url中的中文参数是GB2312还是Utf-8编码