Database platform 2

xiaoxiao2021-03-06  41

1. Operating environment: JDK, Oracle9i or above, Castor package. It is recommended to use the JBuilde tool to develop 2. Usage Environment: Use ORM (Relational Object Mapping) to operate database data for development in Application and Web mode.

3. Function: Provide queries, update, delete, insert (did not implement automatic generation of primary keys), ("Pipe is temporarily not implemented). 4. Use the steps: First create a CAT table in the database, the field is CAT_ID; Name; SEX; Weight; Type 1, 4 is digital, 2, 3 is a string type.

Secondly establish two profiles (defined by yourself): repository.xml configuration information:

CAT cat_id </ title> </ fielddsc> <fieldDesc name =" Name "FieldType =" java.lang.string "> <title> name </ title> </ fielddesc> <fieldDesc name =" sex "fieldType =" java.lang.String "> <title> sex </ title> </ FieldDesc> <FieldDesc Name = "Weight" fieldType = "java.lang.long"> <title> Weight </ title> </ fileDesc> </ TableDesc> </ repository> configuration file design description is as follows: TableDesc means a table statement of. Execid is the best and the table name in general (easy to find the correspondence), but it is not allowed to appear. Note that this class name is not a full path. The primary key in the DentifyField table, if the composite primary key is separated by a comma table name <FieldDesc name = "sex" fieldType = "java.lang.string"> <title> sex </ title> </ fieldDesc> Here Is a description of the fields in the table, name is the field name. FieldType is the type of database field corresponding to Java, only 4 types of fill: java.lang.string, java.lang.long, java.util.date, java.lang.doubleTitle is not. If there is multiple tables Then add the table description between </ TableDesc> and </ repository>.</p> <p>Pool-config.xml configuration information: <? XML Version = "1.0" encoding = "GB2312"?> <resourceparams> <maxactive> 10 </ maxactive> <maxidle> 5 </ maxidle> <maxwait> 10000 </ maxwait> <username> Test </ username> <password> test </ password> <driverclassname> Oracle.jdbc.driver.OracleDriver </ driverclassname> <URL> JDBC: Oracle: Thin: @ 192.168.0.90: 1521: Forecast </ url > <removeabandoned> True </ removeabandoned> <removeabandonedtimeout> 60 </ limitedabandONEDTimeout> <logabandONED> True </ logabandoned> </ resourceParams> Save the above information as an XML file. Not much explanation for this file.</p> <p>Determine that two files already exist, then create a table CAT. There is also a table corresponding to the table. Below is the VO I created in an example of Hibernate. (Borrow) Package com.cea.boat.dao; import java.util. *; Public class cat information cloneable {// declare field private java.lang.string catid; private java.lang.string name; private java.lang. String sex; private java.lang.long weight; // Get method public java.lang.string getcatid () {return.string getName () {return.String GetSex () {Return SEX;} public java.lang.long getWeight () {return weight;} // set method public void setcatid (java.lang.string catid) {this.catid = catid;} public void setname (Java. Lang.string name) {this.name = name;} public void setsex (java.lang.string sex) {this.sex = sex;} public void setWeight (java.lang.long weight) {this.Long Weight } Public object clone () {Object o = null; try {= super.clone ();} catch (clonenotsupportedexception ex) {system.out.println (o); } Return O;} public boolean equals (object obj) {cat o = (cat) obj; boolean results = true && (catid == o.catid || catid.equals (o.catid)) && (name == O .name || Name.Equals (.name)) && (Sex == O.SEX || SEX.EQUALS (O.SEX)) && (Weight == O.Weight || Weight.Equals (O.WEight) ); Return Result;}} The thing that has been completed is completed, and below is an example of use.</p> <p>l query: Examples: Void testQuery () throws Exception {{System.setProperty (Const.RUN_KEY, Const.POOL_FACTORY_KEY); System.setProperty (Const.CONFIG_PATH, "E: /project/CEAConnection/pool-config.xml") ; System.setProperty (Const.REPOSITORY_CONFIG_PATH, "E: /project/CEAConnection/repository.xml");} ConnectionManage connectionManage = new ConnectionManage (); connectionManage.activity ( "com.cea.boat.dao.Cat cat"); Query Query = ConnectionManage.createQuery ("Cat. Catid = '1'"); while (query.hasnext ()) {Object [] Objects = query.next (); Cat Cat = (cat) Objects [0];} ConnectionManage.close (); {/: Use the connection pool system.SetProperty (const.run_key, const.pool_factory_key); // Connect pool parameter configuration file system.SetProperty (const.config_path, "e: /project/ceaconnection/pool-config.xml") ; // Profile Specifies System.SetProperty (const.repository_config_path, "e: /project/ceaconnection/repository.xml");}</p> <p>Declare a connection manager, manage database resources, the start of transaction, its life cycle is ended in an end of a transaction, of course, you can also continue to use this instance when this transaction is finished, to create the beginning of the next transaction . Not recommended so use. ConnectionManage DataManage = New ConnectionManage (); Activation To use classes (there must be CAT in the configuration) .boat.dao.cat cat ");</p> <p>Here only needs to give SQL query conditions, such as SQL is Select * from cat cat where cat.catid = '1' then SELECT * from cat cat where here is already finished, you need to do it, if not The condition is empty. Query query = connectionManage.createQuery ("cat. Catid = '1'");</p> <p>Query.hasNext () The role is equivalent to see if there is still a record, query.next () returns an object array here if Activity is multiple objects, then the Objects will sequentially store the corresponding object instance, It is possible to force transformation when using it. While (query.hasnext ()) {Object [] Objects = query.next (); Cat Cat = (CAT) Objects [0];} Used, release the database resource connectManage.close ();</p> <p>l New way: Since there is no primary key automatically generated, the primary key can only be maintained by yourself, to ensure that the CATID is 111 does not exist in the table, otherwise it will appear. Void testinsert () throws exception {cat (); Cat. Setcatid ("111"); CAT. Setsex ("f"); Cat. SetName ("CATM"); connectionManage cm = new connectionManage (); CM.CREATE (CAT); cm.commit (); cm.close ();</p> <p>l Update: There is a cat that has a Catid 111 in the form, otherwise it will not be updated to update the message void testUpdate () throws exception {cat cat = new cat (); Cat. setcatid ("111"); CAT Setsex ("f"); Cat. SetName ("CATMM"); connectionManage cm = new connectionManage (); cm.Update (cat); cm.commit (); cm.close ();</p> <p>l Delete mode: Delete mode is relatively simple, as long as the object is given, and the key value is not empty, you can delete the table record. Void Testdelete () throws exception {cat Cat = new cat (); Cat. Setcatid ("111"); connectionManage cm = new connectionManage (); cm.delete (cat); cm.commit (); cm.close () }</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-69635.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="69635" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'diU6TEkB8X0yddO_2F_2F3oLVtsBD2JvrRc0RiwxtEPcj_2BmJ3HiOsPw1AZC9NYFVtBu2L_2Fq4RhMenh87IHVUooTjPw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>