CN103809944A - Web database development component processing method based on JDBC - Google Patents

Web database development component processing method based on JDBC Download PDF

Info

Publication number
CN103809944A
CN103809944A CN201210441628.6A CN201210441628A CN103809944A CN 103809944 A CN103809944 A CN 103809944A CN 201210441628 A CN201210441628 A CN 201210441628A CN 103809944 A CN103809944 A CN 103809944A
Authority
CN
China
Prior art keywords
data
class
jdbc
database
type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201210441628.6A
Other languages
Chinese (zh)
Inventor
罗正伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZHENJIANG HUAYANG INFORMATION TECHNOLOGY CO LTD
Original Assignee
ZHENJIANG HUAYANG INFORMATION TECHNOLOGY CO LTD
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZHENJIANG HUAYANG INFORMATION TECHNOLOGY CO LTD filed Critical ZHENJIANG HUAYANG INFORMATION TECHNOLOGY CO LTD
Priority to CN201210441628.6A priority Critical patent/CN103809944A/en
Publication of CN103809944A publication Critical patent/CN103809944A/en
Pending legal-status Critical Current

Links

Abstract

Disclosed is a web database development component processing method based on JDBC. The whole JDBC process is public to programmers by utilizing packaging in the mode of MVC, and the programmers can bypass the complex JDBC process in the development process and just need to take uniform programming interfaces provided by a network database development component into account.

Description

A kind of method of the WEB database development assembly based on JDBC
Technical field
A kind of method of the WEB database development assembly based on JDBC mainly relates to the data storage technology in computer realm.
Background technology
Third generation Web database all carries out inquiry and the management of all operations to database (increase, delete, revise), information by the Intemet browser interface of unified standard, this is fabulous modes for those terminal users, also more adapts to the needs of development and the network interconnection of Intemet technology.The same with many traditional databases, web database is a kind of data warehouse or information repository for user's access, but wcb database is a new research field, there are again many different aspects from conventional database systems, for example: user's difference, the client simplification etc. of architecture difference, access mode difference, access.These differences just, have determined the complicacy of WEB database program.In order to solve this complicacy, each company all releases the solution of oneself one after another, and the concept of middleware is also arisen at the historic moment.
Summary of the invention
Retrieve and there is no to find the application materials about this system aspects by national patent.
JDBC is carried out to objectification improvement, to reaching following effect: 1), by whole number pick storehouse connection procedure encapsulation, mask complicated loaded down with trivial details Connection Step therebetween; 2) allow the JDBC connecting object after encapsulation provide unified DLL (dynamic link library) to programmer, make programmer realize different number pick storehouse operations with same functional based method.
In order to realize the Section 1 of above-mentioned requirements, namely realize the encapsulation that JDBC database connects, first whole JDBC database connection procedure is encapsulated in a class that is called DBAceess.According to the design philosophy of MVC, key-course just in time can be realized the Section 2 in above-mentioned requirements, and therefore the YDBC after objectification connects in class, and key-course is exactly the unified DLL (dynamic link library) providing for programmer.We just need to allow the function of key-course in this Interface realization MVC pattern like this.Expect that final user only need unify DLL (dynamic link library) dialogue with this, and need not comprehend concrete grammar and the details that database connects.In DBAcccss class, create a public method, be called DBControl, then the key-course in whole DBAcccss class using DBControl method.
According to MVC Design Mode thought, whole JDBC developer component is divided into three layers by we: presentation layer, key-course and model layer.In DBAccess class, we have encapsulated key-course and model layer.Utilize public method DBControl to realize rough handling and the data distribution of user's request, utilize four private methods to realize respectively the database manipulation request that user is different.Create in addition the performance that two assisted class Const classes and Data class improve whole number pick storehouse Ji and send out assembly.
The realization of Const class:
Create in addition a Const class, be used for specially storing the needed various constants of whole program, the global variable storage using above-mentioned each string variable as Const class.In the time that needs connect, extract respective symbols string variable from Const class and pass to DBAccess class, in the time that the selected database product of system is changed, we only need to recompilate the Const class of these parameters of storage.
The code of const class:
public final class Const{
public static string SQLDRIVERNAME=”org.git.mm.mysql.Driver”;
public static string SQLURL=”jdbc:mysql://DLMUDXF/TEXT”;
public static string SQLUSERID=”ROOT”;
public static string SQLPASSWORD=””;
}
Wherein SQLDRIVERNAME storage JDBC database connects needed database device name.The address of SQLURL stored data base.The user name that SQLUSERID storage log database is used.SQLPASSWORD storage login password.The Database Systems that connect as JDBC are while changing, or the correlation parameter of this system changes, and we only need to revise respective field in Const class.
The realization of Data class:
Data class is improved and is obtained in Hashtable type basis, and he is a kind of data type that is suitable for storing number pick library inquiry result set.Therefore, in Data class, we have designed three main privately owned attributes, deposit relevant data with card.
Private Hashtable data=null;
Private int index=-1;
Private Vector columnNameVec=null;
Wherein private Hashtable data is finally used for the Hash table of stored data base query results.Private im index is user's needed virtual mouse in the time using Data object.Private Vector columnNameVec is a vector, is used for the row name of stored data base query results, namely inquires the field names of last number pick storehouse table.Why this cover uses this data structure of Vector vector, is mainly the feature of considering that Vecmr vector can self extending.Because in actual use, we are little definite field a few days of database table of inquiry, and it is flexibly this that therefore we need Vector vector, and number pick structures that can own collapsing length are stored corresponding database table field name.These three attributes are all configured to private type private variable, and this also meets OO encapsulation thought.If user needs three attributes of winner, can not directly read them, and must obtain by corresponding functional based method.Therefore we have defined three functional based methods in Data class, are used for specially obtaining corresponding attribute.For example, if want to obtain private Hashtable data, programmer must pass through getTable method.The code of GetTable method is as follows:
Public Hashtable gettable(){
Return data;
}
T p_da curses) method, this is also the initialization function of Data class.Its function is that the parameter p _ data of the ResultSet type to importing into carries out data destructing, and stores in Hashtable data.The specific code of public Dat ") method is as follows:
public Data(ResultSet p_data){
try{
this.data=new Hashtable0;
im fieldCount 2 p_data.getMetaDataO.getColumnCountO;
columnNameVec=new Vector();
for(inti=1;i<=fieldCount;i++){
String columnName 5 p_data.getMetaData0.getColumnName(i);
columnNameVec.addElement(colunmName);
Vector columnValue=new Vector();
this.data.put(columnName,columnValue);
)
int recordNum=O:
while(p data.next()){
recordNum++;
For (intj 21; J<_fieldCount; J+ ten)
String columnName 2 p-data.getMetaData0.getColumnName(j);
int columnType。p_data.getMetaData0.getColunmType(j);
Object value=null;
switch(columnType){
case java.sql.Types.TIMESTAMP:
case java.sql.Types.DATE:
case java.sql.Types.TIME:
value 2 p_data.getTimestamp(eolumnName);
break;
default:
String tempValue
5 p_data.getString(columnName);
if(tempValue 12 null)
value=new String(tempValue);
break;
}
if“(vector)this.data.get(columnName)).size0<recordNum){
((Vector)this.data.get(columnName)).addElement(value);
}
)
}
this.data.put(”data_size”,new Integer(recordNum));
}catch(SQLException sqlException){
System.out.println(”There are some sqlexception”);
}catch(Exception ioException){
System.out.println(”There are some ioException”);
)
)
First the parameter of Data method is the p_data of ResultSet type, is designed with so very large benefit.When programmer uses Data type to create Data object instance, transmit the ResultSet result set of coming in, can automatically be processed by this Data method, and deposit in Data object instance.
int fieldCount=p_data.getMetaData0.getColunmCount0;
columnNameVec=new Vector();
for(inti=l;i<_fieldCount;i++){
Stnng columnName=p_data.getMetaData0.getColumnName(i);
columnNameVec.addElement(columnName);
Vector columnValue=new Vector();
this.data.put(columnName,columnValue);
}
The effect of this section of code is above the number that obtains the field that comprises of ResultSet result set of transmitting, and the title of each field is deposited in vectorial columnNameVec.Meanwhile, the establishment that the field that comprises in each ResultSet result set is corresponding a vectorial eolunmValue, and these vectorial examples are put into data.That is to say, the field comprising in each ResultSet result set, an all corresponding vector, these vectors are by all data of corresponding field in card storage ResultSet result set.Understand intuitively, above each vector, the row in fact corresponding the ResultSet result set obtaining.We also just understand to have used this data structure of vectorial Vector why like this, exactly because the length of row might not in this ResultSet result set.That is to say ResultSet result set record number might not, therefore want vectorial Vector type flexible and convenient to use.Int recordNum is afterwards used for storing the number that records of ResultSet result set.Ensuing while (p_data.next0) circulation is the part of most critical in whole Data method again, and in this part, we have realized the conversion from ResultSet type to Data type just.While (p_data.next ()) circulation once circulates for the record of each ResultSet result set, and namely each row of ResultSet result set once circulates.In so once circulating, we mainly complete following work: RecordNum note spring number and add one.
The second, carry out again interior loop one time for each row in every a line, this is by for (intj=1; J "=fieldCount; J++1 realizes.We have had two-layer circulation now, and like this for this 2-D data structure of ResultSet result set, the node that we can intersect for each ranks has operated.In Data method, we are just by the processing relevant to each node, realize conversion from ResultSet type to Data type.
On each node, we have mainly completed two parts work.First we judge the data type of this node, and take diverse ways the data of this node to be changed into the value of unified Object type according to the result of judgement.Secondly, the value value that we obtain each node, is deposited among each vector of previously described data.
Why we will judge the data type of node, be that ResultSet class provides different disposal routes because for different data types.This judgement judges that by branch statement switch (columnType) realizes.In this switch branched structure, each case variable is below all the Int type constant that Java itself provides.By coupling, we can select suitable method to get the different number pick type of each node.For example, we can use getTimestamp method to obtain the various time categorical datas in database, and by getString, we can obtain other various types of data.And why different number pick types is all converted to Object type, be because consider that finally they will be stored in the Hashtable data of Hash table structure.This cover uses Object type also to have reason.Object class is a most basic class in Java language, can say that other all classes are all the subclasses of Object class.Therefore we can be Object class by every other conversion in type, and the data of Object type are again converted to original data type by the forced type method for transformation that can provide by Java again in use.
Finally we are by ((Vector) this.data.get (columnName)) .addElement (value); The value value that this method obtains each node is deposited among each vector of data.After two-layer circulation finishes, we have obtained the data object of a Hashtable type.In this data object, each element is a vector, each vector corresponding row of database.And programmer is using data object Shi Hui according to the title of different vectors, the namely field name of database, obtains a corresponding column data.Finally obtain the data value of the node needing according to the line number at node place.Data class also provides several method for reading data in addition, getString, getInt, getDate etc., and they are used for obtaining the data of corresponding data type.
The realization of DBAccess class:
State, DBAccess class is the core classes of whole WEB database development assembly, and database connects and the execution of SQL literary composition all realizes in this class.Utilize MVC pattern, we realize the shunting to user's request using the DBControl method in DBAccess class as controller; Utilize sqlRetumResultSet, sqlReturnData, these four kinds of methods of sqlRetumString, executeUrIdate to process respectively the different solicit operations of user to database, and obtain the rreturn value of the different types of data of user's expectation.
The realization of DBOontro I method:
public synchronized Object DBControl(Stfing strSQL,int dbcode){
Object obj=null;
switch(dbcode){
casel:
String[][】Stringresult=sqlReturnString(strSQL);
obj2Stringresult;
break;
case2:
Data dataresult=sqlReturnData(strSQL);
obj=dataresult;
break;
case 3:
ResultSet rsresult=sqlRetumResultSet(strSQL);
obj。rsresult;
break;
case4:
boolean rsboolean=executeUpdate(strSQL);
if(rsboolean=-lrue){
obj=”true”:
}else{
obj=”false”;
}
break;
default:
break;
}
return obj;
}
The parameter of DBControl method has two, and strSQL is that user expects the SQL statement of carrying out; Dbcode is the type codes of the rreturn value expected of user.In the time of dbeode=l, representative of consumer is expected performing database query manipulation, and expects to return String[] rreturn value of [] type; In the time of dbcode--2, representative of consumer is expected the toilet case used by women in ancient China inquiry operation of actual figure pick storehouse, and expects to return the rreturn value of Data type; In the time of dbcode=3, representative of consumer is expected the operation of actual figure pick library inquiry, and expects to return the rreturn value of ResultSet type; In the time of dbcode=4, representative of consumer is expected actual figure pick storehouse insertion, is deleted or upgrade operation, and expects to return the rreturn value of boolean type.The different value that the shunting of user request has been utilized just to dbcode, carries out the judgement of switch branch, and then determines to call which manner of execution and carry out the SQL statement that user submits to.For example, in the time of dbcode=l, call sqlRetumString method and carry out the query sentence of database that user submits to, and return to String[] rreturn value of fl type.The same with the Slurry pump of Object type in Data class above, because user expects different rreturn value types, we can only be converted into Object type transfer to user by these dissimilar rreturn value unifications.In the time that using, user utilize forced type conversion method that they are converted to the data type that user needs.
The realization of sqlReturnData method:
Because sqlRetumResultSet, the realization of sqlRetumData, sqlRetumString, these four kinds of methods of exeeuteUpdate is more similar; After receiving the SQL statement that user that DBControl method passes over submits to, the realization that sqlRemmDam method is concrete create and maintenance data base connects, creates SQL and carries out container, obtains and this three large step of result collection.These steps complete in ny function body.
try{
connection 2 getConnectionO;
statement=connection.createStatement();
rs=statement.executeQuery(strSQL);
dataresult=new Data(rs);
}
Consider and in whole DBAccess class, have four kinds of methods all need plane to be built in the connection of database, we using this part work extract separately as one independently method realize.This carrys out by a privately owned function getConnection building work that fulfillment database connects with traditional creation method that is connected in not being both.
In sqlRetumData method, this Codabar code of connection=getconnection () has been realized this part function.
In getConnection method, create the needed parameters of connection and all from Const class, pass over.The benefit of doing is like this explanation in detail above, does not run business into particular one and states here.Meet two statement " statement=connection.createStatementO of lower bundle; " and " rs=statement.executeQuery (strSQL) " carried out respectively establishment SQL carry out container, obtain these two steps of result set.Finally utilize the initialization function Data () in Data class to realize to the processing of result set.
Finally, in finally function body, we have completed closing and release work that database connects.
finally(
try{
if(null I-statement){
statement.close0;
statement=null;
)
if(null!=eonnection){
connection.close();
connection=null;
}
}catch(SQLException ex){
System.out.println(”sqlReturnData SQLException!”);
)
}
In sqlReturnData method, completed whole database and connected work for the treatment of, and the rreturn value of having returned to a Data type is to DBControl method, is finally submitted to user by DBControl method.

Claims (4)

1. a method for the WEB database development assembly based on JDBC, is characterized in that, by whole number pick storehouse connection procedure encapsulation, masking complicated loaded down with trivial details Connection Step therebetween; Allow the JDBC connecting object after encapsulation provide unified DLL (dynamic link library) to programmer.
2. according to the requirement of claim 1, whole JDBC developer component is divided into three layers: presentation layer, key-course and model layer.
3. will create DBAccess class according to the requirement of claim 2, its DBAccess has encapsulated key-course and model layer; Utilize public method to realize rough handling and the data distribution of user's request, utilizing four private methods to realize respectively the database manipulation that user is different please; Create the performance that two assisted class Const classes and Data class improve whole number pick storehouse Ji and send out assembly.
4. are the various constants that are stored in road used in whole WEB program according to the major function that requires its Const class of claim 2; Data class is improved and is obtained in Hashtable type basis, and he is a kind of data type that is suitable for storing number pick library inquiry result set.
CN201210441628.6A 2012-11-08 2012-11-08 Web database development component processing method based on JDBC Pending CN103809944A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210441628.6A CN103809944A (en) 2012-11-08 2012-11-08 Web database development component processing method based on JDBC

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210441628.6A CN103809944A (en) 2012-11-08 2012-11-08 Web database development component processing method based on JDBC

Publications (1)

Publication Number Publication Date
CN103809944A true CN103809944A (en) 2014-05-21

Family

ID=50706780

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210441628.6A Pending CN103809944A (en) 2012-11-08 2012-11-08 Web database development component processing method based on JDBC

Country Status (1)

Country Link
CN (1) CN103809944A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105809311A (en) * 2014-12-30 2016-07-27 航天信息股份有限公司 Device and method for invoice information processing
CN106302667A (en) * 2016-08-04 2017-01-04 上海携程商务有限公司 Code management system and method
CN106293688A (en) * 2015-06-26 2017-01-04 阿里巴巴集团控股有限公司 The processing method of a kind of web-page requests, device and system
CN107025249A (en) * 2016-02-02 2017-08-08 上海格尔软件股份有限公司 A kind of method of quick support synchronizing multiple databases exploitation

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030208505A1 (en) * 2002-05-03 2003-11-06 Ward Mullins Dynamic class inheritance and distributed caching with object relational mapping and cartesian model support in a database manipulation and mapping system
CN101853274A (en) * 2010-05-10 2010-10-06 浪潮电子信息产业股份有限公司 Method for realizing interconnection of heterogeneous databases

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030208505A1 (en) * 2002-05-03 2003-11-06 Ward Mullins Dynamic class inheritance and distributed caching with object relational mapping and cartesian model support in a database manipulation and mapping system
CN101853274A (en) * 2010-05-10 2010-10-06 浪潮电子信息产业股份有限公司 Method for realizing interconnection of heterogeneous databases

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
常万军等: "Web程序开发中的JDBC技术改进研究", 《科学之友》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105809311A (en) * 2014-12-30 2016-07-27 航天信息股份有限公司 Device and method for invoice information processing
CN106293688A (en) * 2015-06-26 2017-01-04 阿里巴巴集团控股有限公司 The processing method of a kind of web-page requests, device and system
CN107025249A (en) * 2016-02-02 2017-08-08 上海格尔软件股份有限公司 A kind of method of quick support synchronizing multiple databases exploitation
CN106302667A (en) * 2016-08-04 2017-01-04 上海携程商务有限公司 Code management system and method

Similar Documents

Publication Publication Date Title
US6240422B1 (en) Object to relational database mapping infrastructure in a customer care and billing system
Borkar et al. Big data platforms: What's next?
CN101980213B (en) J2EE-based data persistence method and system
US5956730A (en) Legacy subclassing
CN100468396C (en) Mapping architecture for arbitrary data models
US5937409A (en) Integrating relational databases in an object oriented environment
US6047284A (en) Method and apparatus for object oriented storage and retrieval of data from a relational database
CA2318299C (en) Metadata exchange
US9146955B2 (en) In-memory, columnar database multidimensional analytical view integration
US20070294215A1 (en) Method, system, and program product for generating a virtual database
US20040181538A1 (en) Model definition schema
CN102426582B (en) Data manipulation management devices and data manipulation management method
JPH06175906A (en) Information accumulation system and method
CN101799826A (en) Networking data sharing system and method based on virtual view
CN103559189A (en) Power simulation training resource management system and method based on metadata integration model
US20130031139A1 (en) Multi-input, multi-output-per-input user-defined-function-based database operations
CN103809944A (en) Web database development component processing method based on JDBC
US7325003B2 (en) Method and system for mapping datasources in a metadata model
Kuhn et al. VIP-MDBS: A logic multidatabase system
van der Wolf et al. On the architecture of a CAD framework: The Nelsis approach
Wang et al. Facilitating connectivity in composite information systems
US7574329B1 (en) Object model for decision and issue tracking
van der Wolf et al. Meta data management in the NELSIS CAD framework
CN104572047A (en) Apache Tomcat based WEB database component development method
Moukhi et al. Towards a new method for designing multidimensional models

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140521

WD01 Invention patent application deemed withdrawn after publication