应用集成原理与工具集成实验报告.docx

上传人:b****4 文档编号:24236235 上传时间:2023-05-25 格式:DOCX 页数:24 大小:2.61MB
下载 相关 举报
应用集成原理与工具集成实验报告.docx_第1页
第1页 / 共24页
应用集成原理与工具集成实验报告.docx_第2页
第2页 / 共24页
应用集成原理与工具集成实验报告.docx_第3页
第3页 / 共24页
应用集成原理与工具集成实验报告.docx_第4页
第4页 / 共24页
应用集成原理与工具集成实验报告.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

应用集成原理与工具集成实验报告.docx

《应用集成原理与工具集成实验报告.docx》由会员分享,可在线阅读,更多相关《应用集成原理与工具集成实验报告.docx(24页珍藏版)》请在冰豆网上搜索。

应用集成原理与工具集成实验报告.docx

应用集成原理与工具集成实验报告

应用集成原理与工具集成实验报告

实验环境:

硬件:

PC机、windows10系统

服务器:

运用Tomcat7.0轻量级服务器

开发环境:

JSP、Html、Java、xml

开发工具:

eclipse

实验目的:

一、掌握多个数据库的集成操作

二、熟悉JSP基本开发步骤

三、熟悉javabean的编写

实验内容:

建立多个底层数据库,通过可适应的操作方式对多个数据库进行查询操作。

实验步骤:

1、建立Table类与TableProperty类方便进行表信息的存储

Table类:

packageuil;

importjava.util.List;

/*

*进行表信息的存取

*/

publicclassTable{

privateStringtable_name=null;

privateListtable_property=null;

publicTable(Stringtable_name,Listtable_property){

this.setTable_name(table_name);

this.setTable_property(table_property);

}

publicStringgetTable_name(){

returntable_name;

}

publicvoidsetTable_name(Stringtable_name){

this.table_name=table_name;

}

publicListgetTable_property(){

returntable_property;

}

publicvoidsetTable_property(Listtable_property){

this.table_property=table_property;

}

}

TableProperty类:

packageuil;

/*

*保存表信息

*/

publicclassTableProperty{

privateStringproperty_name=null;

privateStringproperty_type=null;

privateintproperty_length=0;

publicTableProperty(String_property_name,String_property_type,int_property_length){

setProperty_name(_property_name);

setProperty_type(_property_type);

setProperty_length(_property_length);

}

publicStringgetProperty_name(){

returnproperty_name;

}

publicvoidsetProperty_name(Stringproperty_name){

this.property_name=property_name;

}

publicStringgetProperty_type(){

returnproperty_type;

}

publicvoidsetProperty_type(Stringproperty_type){

this.property_type=property_type;

}

publicintgetProperty_length(){

returnproperty_length;

}

publicvoidsetProperty_length(int_property_length){

this.property_length=_property_length;

}

}

2、进行数据库的链接以及数据库xml文件的解析

Connect类:

packagejavabean;

importjava.io.IOException;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.util.ArrayList;

importjava.util.List;

importjavax.xml.parsers.DocumentBuilder;

importjavax.xml.parsers.DocumentBuilderFactory;

importjavax.xml.parsers.ParserConfigurationException;

importorg.w3c.dom.Document;

importorg.w3c.dom.Node;

importorg.w3c.dom.NodeList;

importorg.xml.sax.SAXException;

publicclassConnect{

//连接驱动

privatestaticfinalStringDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";

//连接路径

privatestaticfinalStringURL="jdbc:

sqlserver:

//localhost:

1433;databaseName=";

//定义用户名

privatestaticfinalStringadmin="用户名";

//定义密码

privatestaticfinalStringpassword="密码";

//通过静态代码块加载驱动

static{

try{

Class.forName(DRIVER);

}catch(ClassNotFoundExceptione1){

//TODOAuto-generatedcatchblock

e1.printStackTrace();

}

}

//获取数据库的连接,返回值为Connection

publicstaticConnectiongetConnection(StringdatabaseName){

Connectionconn=null;

try{

//获取到各数据库的Connection对象,之后进行操作

conn=DriverManager.getConnection(URL+databaseName,admin,password);

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

returnconn;

}

//关闭数据库,注意数据库关闭的顺序

publicstaticvoidclose(ResultSetrs,PreparedStatementps,Connectionconn){

if(rs!

=null){

try{

rs.close();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

rs=null;

}

if(ps!

=null){

try{

ps.close();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

ps=null;

}

if(conn!

=null){

try{

conn.close();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

conn=null;

}

}

/*

*对xml文件中拥有的数据库资源进行解析

*/

publicstaticListgetDatabaseName(){

Listdatabase=newArrayList();

DocumentBuilderFactoryfb=DocumentBuilderFactory.newInstance();

DocumentBuilderdb=null;

try{

db=fb.newDocumentBuilder();

Documentdoc=db.parse("C:

\\Users\\lenovo\\Desktop\\ecilpse\\TestJS\\WebContent\\database.xml");

NodeListnodeList=doc.getElementsByTagName("database_name");

for(inti=0;i

database.add(nodeList.item(i).getTextContent());

}

}catch(ParserConfigurationExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}catch(SAXExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

returndatabase;

}

}

3、进行数据库中表信息的获取以及表属性类型适配

QueryAll类:

packagejavabean;

importjava.sql.Connection;

importjava.sql.DatabaseMetaData;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

importjava.util.ArrayList;

importjava.util.List;

importuil.Table;

importuil.TableProperty;

/*

*进行所有数据库信息的查询

*/

publicclassQueryAll{

/*

*测试主函数

*/

publicstaticvoidmain(String[]args){

try{

showData();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

/*

*进行数据库表信息的获取

*/

publicstaticList

getTable(Connectionconn)throwsSQLException{

List

table_list=newArrayList
();

ResultSetrs=null;

DatabaseMetaDatadata=conn.getMetaData();

rs=data.getTables(null,null,null,newString[]{"TABLE"});//获取到该数据库所有的表名

ResultSetrs1=null;

while(rs.next()){

Tabletable=newTable(null,null);

ListtableProperty=newArrayList();

table.setTable_name(rs.getString("TABLE_NAME"));

rs1=data.getColumns(null,"%",rs.getString("TABLE_NAME"),"%");

while(rs1.next()){

StringcolumnName=rs1.getString("COLUMN_NAME");

StringcolumnType=rs1.getString("TYPE_NAME");

intdatasize=rs1.getInt("COLUMN_SIZE");

tableProperty.add(newTableProperty(columnName,columnType,datasize));

}

table.setTable_property(tableProperty);

table_list.add(table);

}

returntable_list;

}

/*

*获取数据库中的连接对象

*/

publicstaticvoidshowData()throwsSQLException{

Connectionconn=null;

ListdatabaseName=Connect.getDatabaseName();

for(inti=0;i

conn=Connect.getConnection(databaseName.get(i));

System.out.println(databaseName.get(i));

List

tables=getTable(conn);

for(intj=0;j

System.out.println(tables.get(j).getTable_name());

Listpropertys=tables.get(j).getTable_property();

for(intk=0;k

System.out.println(propertys.get(k).getProperty_name()+""+propertys.get(k).getProperty_type()+""+propertys.get(k).getProperty_length());

}

query(conn,tables.get(j));

}

}

}

/*

*进行具体信息的查询

*/

publicstaticvoidquery(Connectionconn,Tabletable)throwsSQLException{

Stringsql="select*from"+table.getTable_name();

Statementst=conn.createStatement();

ResultSetrs=null;

rs=st.executeQuery(sql);

matching(rs,table.getTable_property(),null);

}

/*

*进行数据类型的匹配

*/

publicstaticbooleanmatching(ResultSetrs,ListtablePropertys,Listlist)throwsSQLException{

booleanresult=false;

while(rs.next()){

StringBuildersc=newStringBuilder();

for(inti=0;i

if(tablePropertys.get(i).getProperty_type().equals("intidentity")||tablePropertys.get(i).getProperty_type().equals("int")){

sc.append(rs.getInt(i+1)+"");

//System.out.print(rs.getInt(i+1)+"");

}elseif(tablePropertys.get(i).getProperty_type().equals("float")){

sc.append(rs.getInt(i+1)+"");

//System.out.print(rs.getInt(i+1)+"");

}elseif(tablePropertys.get(i).getProperty_type().equals("nvarchar")||tablePropertys.get(i).getProperty_type().equals("varchar")){

sc.append(rs.getString(i+1)+"");

//System.out.print(rs.getString(i+1)+"");

}

}

list.add(sc.toString());

result=true;

System.out.println("");

}

returnresult;

}

}

4、进行输入信息的适配以及数据查询

SearchData类:

packagejavabean;

importjava.math.BigDecimal;

importjava.sql.Connection;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

importjava.util.ArrayList;

importjava.util.List;

importuil.Table;

/*

*根据输入的信息在数据库中进行检索

*/

publicclassSearchData{

/*

*测试主函数

*/

publicstaticvoidmain(String[]args){

}

/*

*根据信息进行检索

*/

publicstaticvoidsearch(Stringmessage,Listlist){

ListdatabaseName=newArrayList();

databaseName=Connect.getDatabaseName();//获取数据库名称

if(!

isNum(message)){

message="%"+message+"%";//非String类型时加上通配符进行查询

}

System.out.println(message);

for(inti=0;i

Connectionconn=null;

//System.out.println("Theinformationin"+databaseName.get(i));

conn=Connect.getConnection(databaseName.get(i));//获取该数据库的连接对象

List

tables=null;

try{

tables=QueryAll.getTable(conn);//进行该数据库的表查询

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

/*

*根据查询信息在各表中进行检索

*/

for(intj=0;j

//对各表中的各属性进行检索

for(intk=0;k

Stringsql="select*from"+tables.get(j).getTable_name()+"where"+tables.get(j).getTable_property().get(k).getProperty_name()

+"like\'"+mes

展开阅读全文
相关搜索

当前位置:首页 > 解决方案 > 商业计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1