The amount of data in a database is large, but it is not possible to delete it while also optimizing the program to retrieve the data time.
A: There are many ways such as creating database table partitions, creating indexes, stored procedures, etc. I use this method of dynamically creating database Tables .
can be implemented without creating table partitions, such as the logging table will be the default table suffix dynamic append yyyy-mm, such as the article publishing table to the user name as a suffix dynamic append ;
The way to create database tables dynamically is to specifically analyze specific problems, such as using the CREATE TABLE table name _dynamicstr (...) directly in JDBC.
Article Publishing System DYNAMICSTR can use registered login username , log table Dynamicstr can use ' Log_ ' +new simpledateformat ("Yyyymm"). Format (new Date ());
The following example is an example of dynamically creating a database table using Hibernate and, if interested, can extract the following code into a dynamically created table Utils.
Public classReportdbapi {PrivateSessionfactory sessionfactory =NULL; PublicReportdbapi () {createsession (); } Public voidcreatesession () {Date Date=NewDate (); SimpleDateFormat SimpleDateFormat=NewSimpleDateFormat ("YyyyMMdd"); String Now_time=Simpledateformat.format (date); String TableName= "tbl_report_status_20050707"; TableName= "Tbl_report_status_" +Now_time; Try{Configuration cfg=NewConfiguration (). addclass (Cn.sports.vas.sms.unicom.TblReportStatus.class). Configure (); Table Table= Cfg.getclassmapping (tblreportstatus.class). getTable (); Table.setname (tablename); Cfg.getclassmapping (tblreportstatus.class). settable (table); Sessionfactory=cfg.buildsessionfactory (); } Catch(Mappingexception ex) {ex.printstacktrace (); }Catch(Hibernateexception ex) {ex.printstacktrace (); } } Public voidINSERTPO (Tblreportstatus po)throwsHibernateexception {Session session=sessionfactory.opensession (); Transaction TX=session.begintransaction (); Session.save (PO); Tx.commit (); Session.close (); } Public voidCloseSession ()throwshibernateexception {sessionfactory.close (); }}