Mysql in the database and create a user

  Abstract: mysql database users and create 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> 1. Your root login to use mysql, and methods: 
  C: \ mysql \ bin \ mysql-uroot-p 
  2. Javauser to create a user with the password javadude, has competence: at any of the database on the mainframe operating arbitrary javatest 
  Mysql> GRANT ALL PRIVILEGES ON javatest .* TO javauser @ "%" 
  –> IDENTIFIED BY "javadude"; 

  <table Width="665" height="31" border="0"> <tr> <td width="365" valign="top"> 3 Create Database 

  Mysql> create database javatest; 

  4. Create Table 
  Mysql> use javatest; 
  Mysql> create table testdata ( 
  –> Id int not null auto_increment primary key, 
  –> Foo varchar (25), 
  –> Bar int); 

  5. Insert the few 

  Mysql> insert into testdata values (null, 'hello', 12345); 
  Query OK, a row affected (0.00 sec) 

  Mysql> select * from testdata; </ td> <td width="290"> </ td> </ tr> </ table> 
+—-+——-+——-+
  | ID | FOO | BAR | 
+—-+——-+——-+
  | 1 | hello | 12345 | 
+—-+——-+——-+
  1 row in set (0.00 sec) 

  Mysql> </ td> </ tr> <tr> 

  ↑ Back 

Based on the message boards Hibernate - HiMessage

  Abstract: Based on the message board Hibernate - HiMessage 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td height="51" align="center" valign="top"> </ td> </ tr> <tr> <td height="20"> 

  HiMessage book www.tiandinet.com 
  You are welcome to use "HiMessage book!"    You are currently using version 1.0. 
  "HiMessage book" is a book based on the Hibernate support the recovery picture upload function, as well as basic message management, system capabilities. 

  Graph: 

============
  Agreements on the use of procedures 
============
  1, the procedures you can use free of charge to any form of the use of "HiMessage book," but can not be used for commercial purposes.    Any use of "HiMessage book" and the consequences, "Heaven and Earth network" does not assume any responsibility or jointly and severally liable.    In your free use "HiMessage book" At the same time, to retain all copyright information, which includes display on the top of the page, the page at the bottom of the copyright information and procedures (including Java, JSP, SQL, and HTML documents, etc. ) of the Copyright Notes.    If you wish to some procedures or page understandable changes, please contact tiandinet_support@hotmail.com, it is necessary to carry out these changes you need to be "world network" authorization. 

  2, the spread of procedures 
  Guarantee the procedure has not been changed circumstances, in any way you can spread the program.    "Heaven and Earth Network" to "HiMessage book," All rights reserved. 

============
  Installation 
============

  1, set up a data table: the MySQL database into the SQL directory himessage-MySQL.sql need to establish procedures for the data table. 
  2, the establishment of Context: Context Tomcat in the new one, so at the docBase procedures directory (if you download the document is war, then at the paper). 
  3, the database connection settings: Laws WEB-INF/classes/hibernate.cfg.xml paper, which is Hibernate configuration files. 

  Upon completion, which is passed to visit http:/// "HiMessage book" (need to restart Tomcat). 

  Administrators default user name / password is: admin / 123456. 

  In the process of installing Step 2 Tomcat can be used to complete the Administration Tool (Servlet other similar containers).    In the directory under the Context example set reference document (the document automatically generated by the Tomcat). 

============
  Other information 
============
  1, you can access procedures to the "Network World" (http://www.tiandinet.com) Download "HiMessage book", but can also download other procedures. 

  2, the development and testing environment 
  Windows XP SP2 (English Version) 
  Tomcat 5.5.9 
  J2SDK 1.5.0_02 
  MySQL 3.23.52 / 4.0.18 
  MySQL Connector / J 3.1.8 
  Hibernate 3.0.3 

  3, or BUG 
  In the course of your use of any of the puzzling discovery or BUG, you can: 

  1) to the site of the book (http://www.tiandinet.com/guestbook/) Message 
  2), E-mail to tiandinet_support@hotmail.com (please specify theme: Network World) 
  3) Contact this site technical support QQ: 254753722 

  Thank you!    More procedures to http://www.tiandinet.com please. 
  Network World 
  July 12, 2005 

  </ Td> </ tr> </ table> </ td> </ tr> <tr> 

  ↑ Back 

Simple JDBC applications for Java DB

  Abstract: simple JDBC applications for Java DB 

  </ Td> </ tr> <tr> <td height="3302" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td height="62" align="left" valign="top"> </ td> </ tr> </ table> 

  Jdk1.6.0 downloaded today, should be carried out slowly after learning of the new features in 1.6 and some of these classic examples.    Let us first look at the java DB on the most simple examples: 
  Simple JDBC Application (OSS SimpleApp.java, documents and derby.jar, derbynet.jar, derbyclient.ar documents sought from the jdk1.6.0) 

  This example is a minimum JDBC applications.    On the procedures: 

  •   Built-in mode (the default) or as a server environment, the client operation, which depends on the parameters passed to the procedure 
  •   If you are running in the embedded pattern, then start the engine Derby 
  •   If you are running in client mode, connected to the Derby network server 
  •   Create and connect to the database 
  •   Create a Table 
  •   Inserting 
  •   Updated data 
  •   Enquiries data 
  •   Delete Table 
  •   Close connections 
  •   If you are running in the embedded mode, the closure of Derby. 

  Following is the source: 

  Import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; / * * @ author janet * / public class SimpleApp (/ * default mode is embedded * / public String framework = "embedded"; public String driver = "org.apache.derby.jdbc.EmbeddedDriver" public String protocol = "jdbc: derby: "; public static void main (String [] args) (new SimpleApp (). go (args);) void go (String [] args) (/ * parameter to determine the procedure to use as embedded or as a client use * / parseArguments (args); System.out.println ( "SimpleApp starting in the" + + framework "mode."); try (/ * load drivers, if it is embedded model, which will activate the Derby, because It also is not running. * / Class.forName (driver). newInstance (); System.out.println ( "Loaded the appropriate driver."); Connection conn = null; Properties props = new Properties (); props.put ( "user", "user1"); props.put ( "password", "user1"); / / create = true to create database derbyDB conn = DriverManager.getConnection (protocol + "derbyDB; create = true", props); System.out.println ( "Connected to and created database derbyDB"); conn.setAutoCommit (false); / / automatic mode to the Statement s = conn.createStatement () / * Create a table, by adding a few records and update 1 * / s.execute ( "create table derbyDB (num int, addr varchar (40 ))"); System.out.println (" Created table derbyDB "); s.execute (" insert into derbyDB values (1956, 'Webster St .')"); System.out.println ( "Inserted 1956 Webster"); s.execute ( "insert into derbyDB values (1910,' Union St .')"); System.out.println (" Inserted 1910 Union "); s.execute (" update derbyDB set num = 180, addr = 'Grand Ave.' where num = 1956 "); System.out.println (" Updated 1956 Webster to 180 Grand "); s. execute ( "update derbyDB set num = 300, addr = 'Lakeshore Ave.' where num = 180"); System.out.println ( "Updated 180 Grand to 300 Lakeshore"); / * Check for and the results * / ResultSet rs = s.executeQuery ( "SELECT num, addr FROM derbyDB ORDER BY num"); if (! rs.next ()) (throw new Exception ( "Wrong number of rows");) if (rs.getInt (1 )! = 300) (throw new Exception ( "Wrong row returned");) if (! rs.next ()) (throw new Exception ( "Wrong number of rows");) if (rs.getInt (1)! = 1910) (throw new Exception ( "Wrong row returned");) if (rs.next ()) (throw new Exception ( "Wrong number of rows");) System.out.println ( "Verified the rows") ; s.execute ( "drop table derbyDB ");// delete Table System.out.println (" Dropped table derbyDB "); rs.close (); s.close (); System.out.println (" Closed result set and statement "); conn.commit (); conn.close (); System.out.println (" Committed transaction and closed connection "); boolean gotSQLExc = false; if (framework.equals (" embedded ")) ( try (DriverManager.getConnection ( "jdbc: derby:; shutdown = true ");// closed database services) catch (SQLException se) (gotSQLExc = true;) if (! gotSQLExc) (System.out.println (" Database did not shut down normally ");) else (System.out.println (" Database shut down normally ");))) catch (Throwable e) (System.out.println (" exception thrown: "); if (e instanceof SQLException) (printSQLError ((SQLException) e);) else (e.printStackTrace ();)) System.out.println ( "SimpleApp finished");) static void printSQLError (SQLException e) (while (e! = null) (System.out.println (e.toString ()); e = e.getNextException ();)) private void parseArguments (String [] args) ( 
  / / System.setProperty ( "derby.system.home", "c: \ \ DBdata ");// this database can be set up data storage directory 

  Int length = args.length; for (int index = 0; index <length; index + +) (if (args [index]. EqualsIgnoreCase ( "jccjdbcclient")) (framework = "jccjdbc"; driver = "com.ibm.db2 . jcc.DB2Driver "protocol =" jdbc: derby: net: / / localhost: 1527 / ";) if (args [index]. equalsIgnoreCase (" derbyclient ")) (framework =" derbyclient "; driver =" org. apache.derby.jdbc.ClientDriver "protocol =" jdbc: derby: / / localhost: 1527 / ";)))) Here is how to run this procedure: First, how in the embedded environment (integrated into desktop applications) I run this example is the working directory c: \ java, first derby.jar copied to the c: \ java \ jar under.    Run.bat write a batch file, as follows: 
  Set CLASSPATH = c: \ java \ jar \ derby.jar; CLASSPATH%% 

  Open windows XP command line window into the working directory.    Run: 
  C: \ java> run.bat 
  C: \ java> set CLASSPATH = c: \ java \ jar \ derby.jar; 
  C: \ java> javac SimpleApp.java 

  C: \ java> java SimpleApp 
  SimpleApp starting in embedded mode. 
  Loaded the appropriate driver. 
  Connected to and created database derbyDB 
  Created table derbyDB 
  Inserted 1956 Webster 
  Inserted 1910 Union 
  Updated 1956 Webster to 180 Grand 
  Updated 180 Grand to 300 Lakeshore 
  Verified the rows 
  Dropped table derbyDB 
  Closed result set and statement 
  Committed transaction and closed connection 
  Database shut down normally 
  SimpleApp finished 

  Operating procedures will be generated in the current directory 

  •   DerbyDB (directory) 
      This directory constitutes a derbyDB database directory. You can not change the document in any directory. 
  •   DerbyDB \ log (directory) 
      This directory is a database kept the transaction log. 
  •   DerbyDB \ seg0 (directory) 
      This directory is a database derbyDB preserve data 
  •   DerbyDB \ service.properties 
      An internal document, preserve some configuration parameters 
  •   Derby.LOG 
      Log files 

  Second, how in the server environment running this example 

  (1) start Derby Network Server 

  Derbynet.jar will be copied to the c: \ java \ jar, run.bat document read: 
  Set CLASSPATH = c: \ java \ jar \ derby.jar c: \ java \ jar \ derbynet.jar; CLASSPATH%% 

  Opened a new DOS command line window, this window activated Derby Network Server, such as: 

  C: \ java> run.bat 

  C: \ java> set CLASSPATH = c: \ java \ jar \ derby.jar c: \ java \ jar \ derbynet.jar; 

  C: \ java> java org.apache.derby.drda.NetworkServerControl start 
  In 1527 for the server port to accept connections. 

  (2) with Derby client mode operation of this procedure: 

  Derbyclient.jar will be copied to the c: \ java \ jar, run.bat document read: 
  Set CLASSPATH = c: \ java \ jar \ derbyclient.jar; CLASSPATH%% 

  Opened a new DOS command line window, and then to Derby client mode activated SimpleApp 

  C: \ java> run.bat 
  C: \ java> set CLASSPATH = c: \ java \ jar \ derbyclient.jar; 

  C: \ java> java SimpleApp derbyclient 
  SimpleApp starting in derbyclient mode. 
  Loaded the appropriate driver. 
  Connected to and created database derbyDB 
  Created table derbyDB 
  Inserted 1956 Webster 
  Inserted 1910 Union 
  Updated 1956 Webster to 180 Grand 
  Updated 180 Grand to 300 Lakeshore 
  Verified the rows 
  Dropped table derbyDB 
  Closed result set and statement 
  Committed transaction and closed connection 
  SimpleApp finished 

  (3) the use of IBM DB2 JDBC Universal Driver running this example 

  10.0 in the Derby version of IBM DB2 JDBC Universal Driver Derby Network Server is the only client-driven. Driver needs from IBM's website (IBM DB2 JDBC Universal Driver, for Apache Derby Network Server). From 10.1, Derby network client driver together with the distribution of Derby, and is recommended by the client-driven process, but also to support DB2 Universal Driver and the same can be used like the following: 

  Download db2jcc.jar and db2jcc_license_c.jar, in the c: \ java \ jar directory, run.bat with the following: 
  Set CLASSPATH = c: \ java \ jar \ db2jcc.jar c: \ java \ jar \ db2jcc_license_c.jar; CLASSPATH%% 

  C: \ java> run.bat 

  C: \ java> set CLASSPATH = c: \ java \ jar \ db2jcc.jar c: \ java \ jar \ db2jcc_license_c.jarr; 

  C: \ java> java SimpleApp jccjdbcclient 

  A successful run produces the following output: 
  SimpleApp starting in jccjdbc mode. 
  Loaded the appropriate driver. 
  Connected to and created database derbyDB 
  Created table derbyDB 
  Inserted 1956 Webster 
  Inserted 1910 Union 
  Updated 1956 Webster to 180 Grand 
  Updated 180 Grand to 300 Lakeshore 
  Verified the rows 
  Dropped table derbyDB 
  Closed result set and statement 
  Committed transaction and closed connection 
  SimpleApp finished </ td> </ tr> <tr> 

  ↑ Back 

Database Services Memorandum

  Abstract: Database Services Memorandum 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="502" height="86" align="left" valign="top"> Services is a group of interdependent operations, a move are not cite examples could be cited is the banking transactions and, of course, other things like online shopping, electronic money transactions, and so on, the Panel depends on the success of the operation of these interdependent whether it can implement successful, as long as there is a failure of operation, which means that the failure of the whole affairs.    For example: tom bill and the QQ account QQ coins points are 500 points, 100 points of the bill now QQ coins to the QQ tom currency accounts, the Panel includes the following actions acts: 
  QQ bill - the currency accounts to reduce 100 points 
  — Tom QQ coins account of an increase of 100 points 

  These two operations as an indivisible unit of work, if only the first step of successful operation, but the failure of the implementation of the second step, then the whole Affairs failed to rollback before the start of the state affairs, the bill and tom QQ account QQ coins Decimal also remains 500 points.    If there is no clear concept of affairs, then the bill will create 100 points QQ coins mysterious disappearance … 
  Database Services is the above-mentioned services in RDB in the realization of it by a group of interdependent business logic in the SQL statement of the assumption that more than DB QQ account in the qq_account table structure as follows: 
————————————
  Id name balance 
————————————
  A bill 500 
  2 tom 500 
————————————

  SQL above matters can be expressed as: 
  UPDATE qq_account SET balance = 400 WHERE id = 1; 
  UPDATE qq_account SET balance = 600 WHERE id = 2; 

  As long as there is a two SQL statements implementation fails, the entire affairs will fail, qq_account data in the table must be moved back to the original state, and will not be updated. 
  Database Services must have ACID properties, the specific meaning of the following: 

  —– Atomic (atom of): the entire database only the work of the Panel is indivisible unit.    Only all of the affairs of successful operation, the entire affairs to be successful in the affairs of any failure of the implementation of a SQL statement, then the implementation has been successful SQL statements must also be revoked, the database should be returned to the implementation of state affairs as before.    Through the above example we have seen very clearly. 

  —– Consistency (consistency): Database Services that can not damage relations between the integrity of the data on the business logic and consistency.    For example, whether the example above QQ coins inside the affairs of transfer success or failure, it should ensure that services in the table after the end of qq_account tom bill and the QQ coins amounted to 1,000 points. 

  —– Isolation (isolation): Concurrency refers to in the environment, different Affairs at the same time when the operation of the same data, each of the services have their own space complete data, the things involved here more , I would like to sum up in the back as a separate article. 

  —– Durability (persistent): Only refer to the successful conclusion of the Panel, which updates the database must be made permanent preservation.    Even in a system crash, restart the database, the database can successfully return to the Panel at the end of the state.    </ Td> <td width="182" valign="top"> </ td> </ tr> </ table> 

  ACID affairs is an abstract concept, the specific RDBMS is achieved.    Log database management system used to ensure that atomic affairs, consistency and sustainability.    Logging Services has done update of the database, if a particular Affairs in the implementation process in the wrong, can log on to remove Affairs has been done on the database update, retreated to the implementation of the database before the initial state affairs.    Therefore, regardless of what the database referred to, will have a chapter devoted speaking log, Oh, and finally, to understand the nature of the role of the log. 

  As for the affairs of isolation, RDBMS is a lock mechanism to achieve.    When more than one Affairs at the same time to update the critical data in the database, only allows holders to lock the affairs of the updated data, other matters must wait until the release of the data before a lock and other matters may only have the opportunity to update, and OS schools in the process of talking about complicated by the lock mechanism almost principle. 

  Mentioned above, the ACID properties database services, then who is going to ensure that the database is ACID affairs?    In fact, as long as the database system to a panel statement, the database system will automatically ensure that the affairs of the ACID properties.    Well Below from abstract concept to see how the statement of affairs: 
  — The beginning of border affairs BEGIN 
  — COMMIT Affairs end of the normal boundaries, submitted to the Panel, the Panel was the permanent preservation of the updated database state. 
  — ROLLBACK abnormal end of the border affairs, withdraw services, data services before returning to the implementation of the initial state. 

  Database System Services support the following two modes: 
  — Automatic submitted mode: each SQL statement is an independent business database system for the implementation of the End of a SQL statement, will be automatically submitted to the Panel. 
  — Manually submitted to the Panel: by the database must be client-specific services in the beginning and the end of the border the border. 

  To MySQL as an example, if we start a MySQL client, it will be an independent database connection.    Each database connection has a global variable @ @ autocommit that current affairs model, it has two selectable values: 

  — 0: that the manual mode. 
  — 1: The default value that the automatic mode. 

  SQL commands can be passed SELECT @ @ autocommit to view current affairs model.    If you want to see the business model to replace manual mode, you can use the following SQL command SET autocommit = 0 to achieve. 

  To say a few more words, MySQL, a database table is divided into three types: INNODB, BDB, MyISAM.    Of the first two types of database support services, and MyISAM table do not support the types of services.    In the use CREATE TABLE command to build the table for the type of default MyISAM, if it wishes to change the DLL can be carried out as follows: 

  ALTER TABLE table_name TYPE = INNODB; 
  If you want to create in the designated table when the type of DLL can be carried out through the following: 

  CREATE TABLE table_name ( 
…..
…..
  ) TYPE = INNODB; 

  Well, we look at below in practice several applications in a statement affairs template. 

  1. MySQL.exe Client Services in a statement 
  We inserted a phrase as an example, of course, is if the automatic mode, each SQL statement is a separate business, we run directly on the following statement: 
  Mysql> INSERT INTO qq_account VALUES ( 'leon', 1000); 

  Below we look at the manual mode in order: 
  Mysql> SET autocommit = 0; 
  Mysql> BEGIN; 
  Mysql> INSERT INTO qq_account VALUES ( 'leon', 1000); 
  Mysql> COMMIT; 

  Such a transaction is complete, Below we look at how best to remove a panel, perhaps you have a very simple guess it 
  Mysql> BEGIN; 
  Mysql> INSERT INTO qq_account VALUES ( 'leon', 1000); 
  Mysql> ROLLBACK; 

  2. JDBC API in a statement Service 
  There is no difficulty, we have to look at the code directly: 
  Connection con = null; 
  Statement stmt = null; 
  Try ( 
  Con = DriverManager.getConnection (dbUrl, dbUser, dbPwd); 
  / / Set to manual mode Service 
  Con.setAutoCommit (false); 
  Stmt = con.createStatement (); 
  Stmt.executeUpdate ("……"); 
  / / Submitted to the Panel 
  Con.commit (); 
  ) Catch (SQLException e) ( 
  If (con! = Null) ( 
  Try ( 
  / / Withdrawal operation is unsuccessful Service 
  Con.rollback (); 
  ) Catch (SQLException e) ( 
……
  ) 
  ) 
……
  Finally () 
  If (con! = Null) ( 
  Try ( 
  If (stmt! = Null) ( 
  Try ( 
  Stmt.close (); 
  ) Catch (SQLException e) ( 
……
  ) 
  ) 
  Con.close (); 
  ) Catch (SQLException e) ( 
……
  ) 
  ) 
  ) 
  Have nothing to say at all, the code has been like a detailed technical articles, it should be noted that the new Connection example, in default under the circumstances, the Panel submitted by the automatic mode, by means con.setAutoCommit (false) Manual mode to set submitted. 

  3. Hibernate API in a statement Service 
  Hibernate Packaging JDBC API and the JTA API, although applications can be bypassed Hibernate API directly through JDBC API and the JTA API to declare affairs, but this is not conducive to the development of cross-platform, we have only to consider the following Hibernate API Implementation: 
  Configuration config = new Configuration (). Configure (); 
  SessionFactory factory = config.buildSessionFactory (); 
  Session session = factory.openSession (); 
  Transation tx = null; 
  Try ( 
  / / Start a Service 
  Tx = session.beginTransaction (); 
  Account account = new Account ( "leon," 1000); 
  Session.save (account); 
  / / Submitted to the Panel 
  Tx.commit (); 
  ) Catch (HibernateException e) ( 
  If (tx! = Null) ( 
  Try ( 
  / / Withdrawal operation is unsuccessful Service 
  Tx.rollback (); 
  ) Catch (HibernateException e) ( 
……
  ) 
  ) 
……
  Finally () 
  If (session! = Null) ( 
  Try ( 
  Session.close (); 
  ) Catch (HibernateException e) ( 
……
  ) 
  ) 
  ) 
  The above code and JDBC API is very similar, it is worth noting that at any time, a Session allow only one not submitted affairs.    Following the code for a Session at the same time did not submit a statement of the two affairs, which is not allowed: 
  Tx1 = session.beginTransaction (); 
  Tx2 = session.beginTransaction (); 
……
  Tx1.commit (); 
  Tx2.commit (); 

  Service with the problem, the first time in learning DB2, it would have been understood, but at that time in order to test, the teacher also did not talk too aware, has been determined to summarize, then, it has been dragged today … gossip talk less, and that is the beginning! 

  In with the environment, a database system will be at the same time for a variety of client services, at the same time running a number of services, visit these matters when the same data in the database, if there is no mechanism to take the necessary isolation, There will be complications, these problems can be summed up as a five: 

  — I lost Update: revocation of a business, and other services has been submitted to the updated data coverage. 
  — Dirty Reading: A Panel read another Affairs did not submit the updated data. 
  — Virtual Reading: A Panel read another Affairs has been submitted to the insertion of new data. 
  Reading - not repeat: a panel read another Affairs has submitted updated data. 
  — The second category lost update: a panel cover other branch of the updating of data has been submitted, this is not a special case of repeated reading. 

  Such a definition is too rigid, but also difficult to understand people, or through an example to careful analysis of each question with the following quote Sunweiqin teachers "proficient Hibernate: JAVA object persistence technology explain" inside examples personally think that this case is pretty good. 

  Now assume that a bank teller a transfer services and a cheque affairs operations with a bank account of the situation, first of all, we assume that the order of implementation of the two affairs, and not with the implementation, then the whole of the following steps: 
  — Bank customers in the banking outlook request withdrawals hundred yuan, the first cashier for account information, that the balance of deposits for 1,000 yuan. 
  — Cashier judgement from the balance of deposits greater than the amount paid to the clients 100 yuan, and the account balance of deposits to 900 yuan. 
  — Dealing with a teller transfer cheques, cheques to the account of this import 100 yuan, the first cashier for account information, that the balance of deposits for 900 yuan. 
  — Teller will deposit balance to 1,000 yuan. 

  Can be very clear that if the implementation of the order of these two services, there will not be any problems, but in reality is not so simple, if the two services by two cashiers at the same time there will be the implementation of it may be complicated The problem, we were to introduce the following: 

  1. First loss update 

  Transfer time teller Affairs Panel 
  ————————————————– —————————————— 
  The start of T1 
  The start of T2 
  T3 account for the balance of 1000 yuan 
  T4 account for the balance of 1000 yuan 
  T5 into the balance of 100 yuan to 1,100 yuan 
  T6 submitted to the Panel 
  T7 out the balance of 100 yuan to 900 yuan 
  T8 revocation affairs for the restoration of the balance of 1,000 yuan 
  ————————————————– ——————————————– 
  If over time in accordance with the concurrent execution of the order, due to transfer services on the cheque deposit balance was updated by the withdrawals covered by the withdrawal of services, customers will lose 100 yuan. 

  2. Dirty Reading 

  Transfer time teller Affairs Panel 
  ————————————————– ——————————————– 
  The start of T1 
  The start of T2 
  T3 account for the balance of 1000 yuan 
T4
  T5 out of the balance of 100 yuan to 900 yuan 
  T6 account for the balance of 900 yuan (dirty Reading) 
  T7 revocation affairs for the restoration of the balance of 1,000 yuan 
  T8 import the balance of 100 yuan to 1,000 yuan 
  T9 submitted to the Panel 
  ————————————————– ——————————————– 
  The cheque for the cash transfer Affairs Panel did not submit the updated data and the results of this enquiry on the basis of the update operation, if withdrawals Affairs was finally withdrawn, bank customers will lead to loss of 100 yuan. 

  3. Virtual Reading 
  Below we give an example to others to see what is false reading. 
  Time Registration Statistical Service 
  ————————————————– ——————————————– 
  The start of T1 
  The start of T2 
  T3 registration statistics, a total of 10,000 people 

  T4 register for a new user 
  T5 submitted to the Panel 
  T6 registration statistics, a total of 10,001 people 
  T7 which in the end statistical data effectively? 
  ————————————————– ——————————————— 

  Statistical Service could not believe the results of inquiries because of the query results is uncertain at any time may be other matters to change. 
  For practical application, will not be in a panel on the same data for two, assuming that the statistical services in the T3 time statistics of the total number of registered customers, to execute a SELECT statement in T6 moment no longer query the database, but print results directly to 10000, Statistics with the results of this database is to be discrepancies between the data, exact, it reflects the state of T3 moment of the data, rather than the current state data.    Should be based on actual need to decide whether to allow Virtual Reading.    Statistical Service in the above example, if only to find out more or less the total number of registered customers, it allows virtual Reading If a panel, will be based on query results to make accurate decision-making, then we must take the necessary services isolation measures to prevent the false reading. 

  4. Not repeat Reading 

  Transfer time teller Affairs Panel 
  ————————————————– ——————————————– 
  The start of T1 
  The start of T2 
  T3 account for the balance of 1000 yuan 
  T4 account for the balance of 1000 yuan 
  T5 out of the balance of 100 yuan to 900 yuan 
  T6 submitted to the Panel 
  T7 account for the balance of 900 yuan 
  T8 balance in the end is 1,000 yuan or 900 yuan? 
  ————————————————– ——————————————— 

  As indicated above, if the two cheques transfer services account deposit balance enquiries, but by a different query results, which makes bank teller could not believe query results, because the query results is uncertain at any time may be other matters to change. 

  5. Second category lost updated 

  Transfer time teller Affairs Panel 
  ————————————————– ——————————————– 
  The start of T1 
  The start of T2 
  T3 account for the balance of 1000 yuan 
  T4 account for the balance of 1000 yuan 
  T5 out of the balance of 100 yuan to 900 yuan 
  T6 submitted to the Panel 
T7
  T8 import the balance of 100 yuan to 1,100 yuan 
  T9 submitted to the Panel 
  ————————————————– ——————————————– 
  Each branch do not know the existence of other matters, a panel on the final record will be updated by the other matters covered by the records submitted by the update.    As the example above, the Panel transfer cheques covering the balance of cash deposits made by the Panel on the upgrading of the losses in the banking final 100 yuan, Hey, do you like to start the second category is not lost update? 
  How can we eliminate these complications?    Please listen next time ……. 

  </ Td> </ tr> <tr> 

  ↑ Back 

Toolbar buttons similar to the procedure

  Abstract: Wizard button similar to the procedure 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="460" height="86" align="left" valign="top"> 

  JAVA prepared by the use of a similar button Wizard procedures, the preparation of documents to support the script. 

  Import java.io. *; 
  Import java.util .*; 
  Import java.awt .*; 
  Import java.awt.event .*; 

  / ** 
  * Support script file keys control procedures 
  * / 
  (Public class KeySprite 
  Public static void main (String [] args) ( 
  String filename = "test.t"; 
  Try ( 
  / / Read configuration files 
  Vector v = readFile (filename); 
  / / Implementation document 
  ParseVector (v); 

  ) Catch (IOException e) ( 
  System.out.println ( "configuration error"); 
  ) Catch (Exception e) ( 
  System.out.println ( "other errors"); 
  ) 
  ) 
  / ** 
  * Read in the paper that Vector 
  * @ Param filepath paper path 
  * / 
  Public static Vector readFile (String filepath) throws IOException ( 
  Vector v = new Vector (); 

  / / Input stream buffer documents 
  BufferedReader br = new BufferedReader ( 
  New InputStreamReader ( 
  New FileInputStream (filepath))); 
  / / Read data 
  String s = br.readLine (); 
  While (s! = Null) ( 
  / / Add to v 
  V.add (s); 
  / / Read the next line 
  S = br.readLine (); 
  ) 
  / / Off input streams 
  Br.close (); 
  / / Return data 
  Return v; 
  ) 

  / ** 
  * Read Vector Analysis, and the operation of the implementation of response 
  * @ Param v Vector object 
  * / 
  Public static void parseVector (Vector v) ( 
  Int size = v.size (); 

  Try ( 
  / / Create Robot Object 
  Robot r = new Robot (); 

  For (int i = 0; i <size; i + +) ( 
  String s = (String) v.get (i); 
  / / Decomposition 
  String [] data = s.split ( ""); 
  / / Implementation Analysis 
  If (data [0]. Equals ( "Mobile")) ( 
  / / Get coordinates 
  Int x = Integer.parseInt (data [1]); 
  Int y = Integer.parseInt (data [2]); 
  / / Mobile 
  R.mouseMove (x, y); 
  ) Else if (data [0]. Equals (the "keys")) ( 
  / / Get keys Category 
  Char c = data [1]. ToLowerCase (). CharAt (0); 
  / / Button 
  R.keyPress (c); 
  / / Release 
  R.keyRelease (c); 
  ) Else if (data [0]. Equals ( "suspended")) ( 
  / / Get suspended time 
  Int time = Integer.parseInt (data [1]); 
  / / Suspended 
  Thread.sleep (time); 
  ) 
  ) 
  ) Catch (Exception e) ( 
  E.printStackTrace (); 
  ) 
  ) 
  ) 

  </ Td> <td width="224" valign="top"> </ td> </ tr> </ table> 

  The script file test.t 

  1000 suspended 
  Mobile 200 300 
  1000 suspended 
  Mobile 210 300 
  1000 suspended 
  Mobile 220 300 
  1000 suspended 
  Mobile 230 300 
  1000 suspended 
  Mobile 240 300 
  1000 suspended 
  Mobile 250 300 
  1000 suspended 
  Mobile 260 300 
  1000 suspended 
  Mobile 270 300 
  1000 suspended 
  Mobile 280 300 
  1000 suspended 
  Mobile 290 300 
  1000 suspended 
  Mobile 300 300 
  1000 suspended 
  Mobile 310 300 

  </ Td> </ tr> <tr> 

  ↑ Back 

How to use jdbtable mysql database connections?

  Abstract: How to use jdbtable mysql database connections? 


  To be an example 



  Jdbtable is synchronized with a show that the content of the database, thank you! 



  Up! 

  Mark! 






  Import java.sql .*; 
  Import javax.swing .*; 
  Import java.awt .*; 
  Import java.awt.event .*; 
  Import java.util .*; 

  Public class inensshow extends JFrame ( 


  Private Connection connection; 
  Private Statement statement; 
  Private ResultSet resultSet; 
  Private ResultSetMetaData rsMetaData; 

  / / GUI variable definitions 
  Private JTable table; 
  Private JTextArea inputQuery; 
  Private JButton submitQuery; 

  Public inensshow () 
  ( 
  / / Form Heading 
  Super ( "input SQL statements, by enquiries button to see the results."); 

  String url = "jdbc: mysql: / / localhost: 3306/web"; 
  String username = "inens"; 
  String password = "inens"; 
  / / Load the driver to connect database 
  Try ( 
  Class.forName ( "org.gjt.mm.mysql.Driver"); 
  Connection = DriverManager.getConnection ( 
  Url, username, password); 
  ) 
  / / Capture abnormal loading drivers 
  Catch (ClassNotFoundException cnfex) ( 
  System.err.println ( 
  "Loading JDBC / ODBC driver failure."); 
  Cnfex.printStackTrace (); 
  System.exit (1); / / terminate program 
  ) 
  / / Catch connecting to the database anomalies 
  Catch (SQLException sqlex) ( 
  System.err.println ( "not connecting to the database"); 
  Sqlex.printStackTrace (); 
  System.exit (1); / / terminate program 
  ) 
  / / If successful database connection, the establishment of GUI 
  / / SQL statement 
  String test = "SELECT * FROM data"; 
  InputQuery = new JTextArea (test, 4, 30); 
  SubmitQuery = new JButton ( "Search"); 
  / / Button incident 
  SubmitQuery.addActionListener ( 
  New ActionListener () ( 
  Public void actionPerformed (ActionEvent e) 
  ( 
  GetTable (); 
  ) 
  ) 
);

  JPanel topPanel = new JPanel (); 
  TopPanel.setLayout (new BorderLayout ()); 
  / / "Input about the" edit box layout to the "CENTER" 
  TopPanel.add (new JScrollPane (inputQuery), BorderLayout.CENTER); 
  / / "To the inquiry" button layout to the "SOUTH" 
  TopPanel.add (submitQuery, BorderLayout.SOUTH); 
  Table = new JTable (); 
  Container c = getContentPane (); 
  C.setLayout (new BorderLayout ()); 
  / / "TopPanel" edit box layout to the "NORTH" 
  C.add (topPanel, BorderLayout.NORTH); 
  / / "Table" edit box layout to the "CENTER" 
  C.add (table, BorderLayout.CENTER); 
  GetTable (); 
  SetSize (500, 300); 
  / / Show Form 
  Show (); 
  ) 

  Private void getTable () 
  ( 
  Try ( 
  / / Implementation of SQL statements 
  String query = inputQuery.getText (); 
  Connection.createStatement statement = (); 
  ResultSet = statement.executeQuery (query); 
  / / In the form of query results show 
  DisplayResultSet (resultSet); 
  ) 
  Catch (SQLException sqlex) ( 
  Sqlex.printStackTrace (); 
  ) 
  ) 

  Private void displayResultSet (ResultSet rs) 
  Throws SQLException 
  ( 
  / / Positioning arrival of the first records 
  Boolean moreRecords = rs.next (); 
  / / If there is no record, a news tips 
  If (! MoreRecords) ( 
  JOptionPane.showMessageDialog (this, 
  "As a result no centralized records"); 
  SetTitle ( "records show"); 
  Return; 
  ) 
  Vector columnHeads = new Vector (); 
  Vector rows = new Vector (); 
  Try ( 
  / / Get the name field 
  ResultSetMetaData rsmd = rs.getMetaData (); 
  For (int i = 1; i <= rsmd.getColumnCount (); + + i) 
  ColumnHeads.addElement (rsmd.getColumnName (i)); 
  / / Get the record set 
  Do ( 
  Rows.addElement (getNextRow (rs, rsmd)); 
  ) While (rs.next ()); 
  / / In the form of query results show 
  Table = new JTable (rows, columnHeads); 
  JScrollPane scroller = new JScrollPane (table); 
  Container c = getContentPane (); 
  C.remove (1); 
  C.add (scroller, BorderLayout.CENTER); 
  / / Refresh Table 
  C.validate (); 
  ) 
  Catch (SQLException sqlex) ( 
  Sqlex.printStackTrace (); 
  ) 
  ) 


  Private Vector getNextRow (ResultSet rs, 
  ResultSetMetaData rsmd) 
  Throws SQLException 
  ( 
  Vector currentRow = new Vector (); 
  For (int i = 1; i <= rsmd.getColumnCount (); + + i) 
  CurrentRow.addElement (rs.getString (i)); 
  / / Return to a record 
  Return currentRow; 
  ) 

  Public void shutDown () 
  ( 
  Try ( 
  / / Disconnect database connection 
  Connection.close (); 
  ) 
  Catch (SQLException sqlex) ( 
  System.err.println ( "Unable to disconnect"); 
  Sqlex.printStackTrace (); 
  ) 
  ) 

  Public static void main (String args []) 
  ( 
  Final inensshow app = 
  New inensshow (); 
  App.addWindowListener ( 
  New WindowAdapter () ( 
  Public void windowClosing (WindowEvent e) 
  ( 
  App.shutDown (); 
  System.exit (0); 
  ) 
  ) 
);
  ) 
  ) 



  ↑ Back 

Java FAQ LIBRARY - from sun.com

  Abstract: Java FAQ LIBRARY - from sun.com 

  : Java FAQ LIBRARY (from the Sun China's official station) 

  Recommended: simon Category: JAVA 

  Java Collection FAQ 

  Q: 

  How to set up Java 2 (JDK1.2) environment variable? 

  Answer: 

Java

  2 After installation, the need for and JAVA_HOME PATH environment variable. With JDK1.1 difference is: Setting up good JAVA_HOME Central 

  Habitat variables, the JVM will automatically search system libraries, as well as users of the current path. 

  Java 2 environment variable settings as in the example below: 

  Solaris platforms: setenv JAVA_HOME Java2 installation path 

  Setenv PATH $ JAVA_HOME / bin: $ PATH) ( 

  Windows platform: set JAVA_HOME the installation path = Java2 

  Set PATH = $ JAVA_HOMEbin;% PATH% 

  Q: What Java integrated development tools support Java 2? 

  Answer: 

  Currently popular Java integrated development environment, such as Inprise of JBuilder, Symantec's Visual Cafe, the PowerJ Sybase, support for the Java 2. 

  Q: 

  If Netscape or IE browser to run Java applet, an error, how to determine wrong? 

  Answer: 

  When the java applet in the browser running, the use of the browser itself is the default JVM. Different JDK browser on the degree of support are not the same. Therefore, in IE or Netscape in the browser to run Java 
  Applet in the wrong, the proposed use of the tools provided appletviewer JDK or Sun's Hotjava browser to test the applet to determine wrong with the selection of browser-related. 

  If the applet or Hotjava appletviewer run all normal, it was the result of the wrong browser does not fully compatible with JDK caused. Time, a solution can be used Hotjava browser or install Sun's Java Plugin. 

  If the applet in the browser or appletviewer Hotjava run error occurs, it should be based on false tips applet inspection procedures. 

  Q: 

  When using JDBC data to the database to insert or extract data from the database, why sometimes Chinese characters will be displayed in chaos? 

  Answer: 

  This problem usually associated with the realization of the achievement of all the JDBC driver. JDBC driver most of the local encoding format used to transmit Chinese characters, such as Chinese characters \ 0 x4175 \ will be transformed into \ 0 x41 \ and the \ 0 x75 \ transfer. Therefore, we need to JDBC driver of the characters and the need to return to the JDBC driver of the characters in the conversion. JDBC driver when used to insert data in the database, there is a need first to Unicode into native code when JDBC driver from the database for data, the need to native code into Unicode. 

  Here is the realization of the two conversion: 

  String native2Unicode (String s) ( 

  If (s == null | | s.length () == 0) ( 

  Return null; 

  ) 

  Byte buffer [] = new byte [s.length ()]; 

  For (int i = 0; i s.length (); i + +) (if (s.charAt (i)> = 0×100) ( 

  C = s.charAt (i); 

  Byte [] buf = (\ \ + c). GetBytes (); 

  Buffer [j + +] = (char) buf [0]; 

  Buffer [j + +] = (char) buf [1]; 

  ) 

  Else ( 

  Buffer [j + +] = s.charAt (i); 

  ) 

  ) 

  Return new String (buffer, 0, j); 

  ) 

  In addition to the above two methods, some JDBC driver if jdbc driver Manager set the correct character set attributes, the above two methods do not need the. 

  Q: 

  When using http Servlet to deal with the return of the request and produce HTML pages, how to make HTML pages in Chinese characters to show that normal? 

  Answer: 

  Javax.servlet.http.HttpResponse category for a return to the site. HttpResponse defined by the method getOutputStream () to get ServletOutputStream example, allowing users to use 
  ServletOutputStream.write ways to write the output stream to return to the content of pages. 

  But ServletOutputStream using the default code, if returned to the pages of Chinese characters to normal, the best show to the designated by the character encoding method. Usually need to construct a OutputStreamWriter routine as follows: 

  Public void doGet (HttpServletRequest req, HttpServletResponse res) 

  Throws ServletException, IOException 

  ( 

  Res.setContentType (\ text / html \; 

  Res.getOutputStream ServletOutputStream out = (); 

  OutputStreamWriter ow = new OutputStreamWriter (out, \ GB2312 \; 

  Ow.write (\ This is the test \; 

  Ow.flush (); 

  Ow.close (); 

  ) 

  Q: 

  How to set up Java WebServer the CLASSPATH to incorporate user class document? 

  Answer: 

  There are two ways to set up Java WebServer the CLASSPATH environment variable, so that users can call Servlet prepared by the user class document. 

  The user's files on JavaWebServer_Dir class / classes directory in the Java WebServer activated, classes directory is automatically added to the CLASSPATH environment variable. 

  Httpd.nojre revised document, which document the user class paths were added to CLASSPATH environment variable. 

  Q: 

  Why in the Windows platform with access to remote Naming.lookup RMI targets will be very slow? 

  Answer: 

  Machinery incorrect network settings is likely to cause the problems. 

  RMI use of the Java network, in particular java.net.InetAddress category, it will for TCP / IP host names, including host names to IP address mapping and host names to IP address mapping. On the Windows platform, such enquiries function is from the local Windows Socket Library to achieve. therefore delay occurs in the Windows library, rather than in the RMI. machines if you use the DNS setting, the problem is usually a DNS server Chabudao host name, you found Delay is DNS query delay. try RMI communications will be involved in all the host / IP address added to the local paper winntsystem 
  32driversetchosts or in windowshosts. Format are as follows: 

  IP addresses hostname 

  It should be set up so can significantly reduce the time spent on. 

  Q: preparation of Java application, how to set up proxy information to external sites to visit? 

  Answer: 

  If the java application of external sites visited, first of all, should be set up proxy information, sample code below: 

  Import java.util.properties; 

…..

  Properties sys = System.getProperties (); 

  Sys.put (\ proxySet \ \ true \; 

  Sys.put (\ proxyHost \ \ myHTTP.proxyserver.com \; 

  Sys.put (\ proxyPort \ \ 80 \; 

  System.setProperties (sys); 

  U = new URL (website); 

  Connect = (HttpURLConnection) u.openConnection (); 

…..

  Q: Swing components JList data revised the list, notice how the show JList change? 

  Answer: 

  JList components have a separate display mode that JList ListModel to display data. 

  JList created after JList data elements and the value of the number of data elements can be dynamically changed. 

  JList in its data model ListModel observed in the data changes. Therefore, a ListModel 
  In the realization of the right of each data should be changed, the monitor to notify the incident. 

  When using the constructor function JList (Object []) creation of a JList example, the system will automatically create a DefaultL 

  IstModel to store JList examples of the display data can be defined in the call DefaultListModel simple method to dynamically modify JList data, such as removeElementAt (index), addElement (Object). 

  DefaultListModel revising data, we will inform the JList on data changes. 

  Q: 
  Java applet in a model of how to achieve the dialog box? 

  Answer: 
  In the Java applet dialog mode to achieve the key lies in the creation of a dialog box for the designated time to correct the father of a window. Is because the Panel Applet subclass category, not the parent window as a dialog box, so the first where to obtain applet window, as a model father dialog window. sample code below: 

…..

  Dialog d = new Dialog (getParentWindow (comp), the title); 

  / / Applet comp for a component of the arbitrary 

….

  Public void getParentWindow (Component compOnApplet, String title) ( 

  Container c = compOnApplet.getParent (); 

  While (c! = Null) ( 

  If (c instanceof Frame) 

  Return (Frame) c; 

  C = c.getParent (); 

  ) 

  Return null; 

  ) 

  Q: How in the Java applet show another HTML pages? 

  Answer: 

  Through java.applet.Applet.getAppletContext () method can be associated with the applet AppletContext, AppletContext.showDocument (URL) method can make the browser applet which shows that another website. 

  Q: 

  Signed by JDK realized applet, can run IE or Netscape? 

  Answer: 

  Signed by JDK realized applet, not IE or Netscape in the run, but can run Hotjava browser 

..

  Different browsers in a different signature applet mechanisms, such as Netscape provide zigbert tools and Capability API, and IE will need to use the CAB files, but whether the signature Netscape tools applet, or by the signature applet IE, not in other browsers run. 

  If the signature JDK applet to run IE or Netscape, the solution is to 

  Netscape, or IE to install Java Plugin, with the signatures of JDK achieve applet can be in these two browsers running. 

  Q: 

  JNI technology can be used from the Java application call C library, but how to make the C library can call another C program? 

  Answer: 

  If a call by the Java C library calls C1 still need another C library C2, C1 in the compiler when the link library C2, the following steps (Solaris platforms): 

  Calling the preparation of the C Java document, and compile it. 

  Javac java file name 

  C header files generated procedures 

  Javah-jni java file name (without suffix. Java) 

  Java was prepared by the C program C1.c call, as well as C1 called C2.c, and compiler. 

  Cc-G-Iinclude pathname C2.c-o libC2.so 

  Cc-G-Iinclude Path - lC2 C1.c-o libC1.so 

  Set environment variables 

  Setenv LD_LIBRARY_PATH libC1.so, where path libC2.so 

  : $ LD_LIBRARY_PATH) ( 

  Applications running java 

  Q: 

  In the Java language, sets out how the PC-all in the file system driver name? 

  Answer: 

  In Java 2 version of the File java.io package of the new method listRoots () function that can be achieved. 

  Q: 

  Why Runtime.exec (\ ls \ No output? 

  Answer: 

  Call Runtime.exec method will produce a local process, and return to a sub-category of Process example, the example in the control of the process or process information. 

  The call Runtime.exec created by the method of the process does not have its own 

  Terminal or console, so that the process of standard IO (stdin, stdou, stderr) through Process.getOutputStream (), Process.getInputStream (), 

  Process.getErrorStream () method to redirect its father 

  The process. User needs to use the stream to the process of obtaining input data or the output of the process. 

  Therefore, the correct implementation 
  Runtime.exec (\ ls \ routine as follows: 

  Try 

  ( 

  Runtime.getRuntime process = (). Exec (command); 

  InputStreamReader ir = newInputStreamReader (process.getInputStream ()); 

  LineNumberReader input = new LineNumberReader (ir); 

  String line; 

  While ((line = input.readLine ())! = Null) 

  System.out.println (line); 

  ) 

  Catch (java.io.IOException e) ( 

  System.err.println (\ IOException \ + e.getMessage ()); 

  ) 

  Q: 

  Signed how applet to enable the applet to access local resources? 

  Answer: 

  In jdk1.1, javakey orders can be used to generate a public key and private key and certificate and signature jar files, and detailed information 

  Please 

  Study: http://java.sun.com/security/usingJavakey.html java2 the signature mechanism and do a relatively great improvement, allowing users more flexibility in setting security permissions. Java2 provides three tools: keytool, policytool and jarsigner Signed applet to achieve, for example, Joe has prepared a signature applet: SignedApplet.java, then create a simple signature applet process is as follows: 

  / / A key, key alias for joe with the password sign12, kept in the key of the joestore 

  Keytool-genkey-alias joe-keypass sign12-keystore joestore 

  / / SignedApplet.class and related documents will be packaged into the jar file 

  Jar cvf SignedAppletDemo.jar 

  / / Use keytool generated by a certificate signed by a self-Signed applet (jar) 

  Jarsigner-keystore joestore-signedjar joe.jar SignedAppletDemo.jar joe 

  / / Self-signed certificate from the output to a file keystore 

  Keytool-export-keystore joestore-alias joe-file joe.cer 

  And the signature of the recipient Susan applet, the need to adopt the following steps to implement security 

  Signed by Joe applet: 

  / / Joe received a certificate and the key to read in the library susanstore 

  Keytool-import-alias joe-file joe.cer-keystore susanstore 

  / / Run Susan policytool meet the requirements of a policy document 

  Policytool 

  / / Use appletviewer operation of, or in the browser installed to run the java plugin. 

  Signed in the applet on the deployment of Java Plugin please refer to the following website: 

  Http://java.sun.com/security/signExample12/ 

  Note: The above examples for the sake of simplicity, the use of the keytool the self-signed certificate. Actually, users can 

  Keytool use to commercial CA-certreq Centre for the e-Cert. 

  Q: 

  If a document through to the ObjectOutputStream repeatedly additional ways to write object, why use ObjectInputStream reads these will be produced StreamCorruptedException object? 

  Answer: 

  Serializetion use of the realization of default, a structure and a ObjectOutputStream ObjectInputS 

  Tream the structure must be one-to-one. ObjectOutputStream constructor will be output to the stream into a first logo, and ObjectInputStream will first read the logo first. Therefore, in many additional ways to write an object in the document, the contains a number of documents will be the first logo. ObjectInputStream so used to deserialize the ObjectOutputStream, will have StreamCorruptedException. a solution can be constructed is an Object 

  OutputStream sub-categories, and cover writeStreamHeader () method. After covering the writeStreamHeader () method should be for the first time to determine whether inclusion in the document object, carbonyl? Super.writeStreamHeader the call (); if not, that is an additional way to write object at all, they should call ObjectOutputStream.reset () method. 

  Q: 

  Object serialization (serialization) is the flow-oriented, it should be how to write object to the random access documents? 
  Answer: 

  Currently, there is no direct way to object can be written to random access file. 

  But ByteArray can use input / output streams as an intermediary, random access to the documents into or from the random access read out in bytes and bytes flow can be used to create targeted input / output streams to be used to read and write Object. needs attention is in the byte stream to include a complete object, it will be targeted at readers in an error. 

  For example, java.io.ByteArrayOutputStream ObjectOutputStream can be used to access the byte stream, which can be byte array can be written to random access file. Contrary, we can randomly access to documents read out in bytes group, it can be constructed using ByteArrayInputStream, thus constructed ObjectInputStream to read object. 

  Q: 

  RMI running applications, can not start naming service rmiregistry manual, but from the start of proceedings? 

  Answer: 

  Can be. 

  Java.rmi provided in the packet of java.rmi.registry.LocateRegistry for access to services or create name names services. Call LocateRegistry.createRegistry (int port) can be created in the name of a particular port, so users no longer need to rmiregistry manually activated. Moreover, LocateRegistry.getRegistry (String host, int port) method can be used to obtain names of services. 

  Q: 

  PrintJob use of print operations, such as how to set up a printer print attributes? 

  Answer: 

  PrintJob use of the following methods can be used to control the printing operation examples: 

  Toolkit.getPrintJob (Frame f, String jobtitle, Properties prop) 

  Then the print attributes can be set up through the prop on the set of attributes to achieve, print attributes include: 

  Awt.print.destination: can \ printer \ or \ file \ 

  Awt.print.printer: printer name 

  Awt.print.fileName: Print the file name 

  Awt.print.numCopies: print shares 

  Awt.print.options: print orders print options 

  Awt.print.orientation: print direction, it could be \ portrait \ or \ landscape \ 

  Awt.print.paperSize: paper size, it could be \ letter \ \ legal \ \ executive \ or \ a4 \ 

  Q: 

  In JDK1.1 definition of the category of Thread suspend () and resume () method, but in JDK1.2 already outdated, what methods should be used to replace them? 

  Answer: 

  Thread.suspend itself easily produce deadlock. Thread if a target of a critical system resources are locked, and then the thread was suspend, then resume unless the threads were, otherwise all other threads will not be able to access the system resources. if another thread will call resume so that the thread continued to operate, and in the meantime, it also needs access to the system resources, will produce deadlock. Therefore, in Java2, more popular way is the definition Thread the state variables, and the target thread Polling state variables, when the state was hoisted state, you can use the wait () method so that it is waiting for the state. thread Once the need to continue the operation, other threads may call notify () method to notify it. 

  Q: 

  Use JDBC programming, the result should be set ResultSet how to control the pointer so that it can moved up and down, and the result set to move to the first line and last line? 

  Answer: 

  In JDK1.1, ResultSet only definition of the category next () method to support the downward movement of data pointer, but in the Java2, ResultSet increase of the following indicators to support the movement of data, including: 

  ResultSet.first (): data pointer to the first row in the result set 

  ResultSet.last (): data pointer to the final result set his 

  ResultSet.previous (): data pointer on his shift 

  In the definition of the above methods JDBC2.0 norms, all support JDBC 

  2.0 JDBC driver can support the above method. Current Intersolv and OpenLink JDBC Driver manufacturers such as a product support JDBC 2.0. 

  Q: 

  Several Web Server which supports Servlet? How IIS support Servlet? 

  Answer: 

  At present, the server-side support Servlet products mainly include: Sun's Java WebServer, Lotus 

  DominoGo WebServer, BEA weblogic Tengah Server, Jigsaw, NetForge, and Mot BaysJetty AcmeServer such. 

  In addition, some third-party vendors have developed a Servlet engine, so that other WebServer (such as Netscape WebServer, IIS, etc.) to run Servlet, such as the Jrun LiveSoftware (http://www.livesoftware.com/products/jrun/). 

  Q: 

  How will image in the Java application to the storage of image files? 

  Answer: 

  Java Advanced Imaging API (included in the Java Media 
  API) allows Java applications in the implementation of complex, high-performance image processing. JAI API provides the ability to store images currently JAIAPI support the following types of image file format 
  : BMP, JEPG, PNG, PNM, TIFF. Below is a BMP image files stored in a section of the code: 

  OutputStream os = new FileOutputStream (fileToWriteTo); 
  ImageEncoder enc = ImageCodec.createImageEncoder (\ BMP \ os, param); 
  Os.close (); 

  The storage of image files Programming Guide please refer to the following website: 

  Http://java.sun.com/products/jav … velopers / jai-guide / 

  Q: 

  How to use the Java language to read and write data serial? Font> 

  Answer: 

  Sun's Java Communication API2.0 can be used to read and write ports, it supports RS232 serial port and IEEE 1284 parallel port, and provides a platform-independent series / parallel port communication mechanism. 
  Detailed document, please visit: http://java.sun.com/products/javacomm/ 

  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

Jdbc on the 1,2,3,4.

  Abstract: jdbc on the 1,2,3,4. 

  Content: On the jdbc 1,2,3,4. 
  Flyblue Reprinted from java technology? [2000-11-16] 

  Mentioned in the title of the \ "1,2,3,4 \" actually refers to the four types jdbc drive. Paper will jdbc driver 
  The four types, as well as different types of driver what level suitable for the application of a simple, 
  If you are ready to develop the database of java applications, you may need to download from the Internet-related databases jdbc 
  Driver. In the download page, you may find that such a statement \ "this is a type 4 drvier \" or this is type 3 should download driver then in the end which, after downloading the driver is suitable for us to develop the application? Or Let us first explain these four types of specific meaning it. 
  Type 1: jdbc-odbc Bridge 
  Type 2: local api drive 
  Type 3: Network Protocol Driver 
  Type 4: Driver local agreement 

  Type 1: jdbc-odbc Bridge 
  Jdbc sun-odbc Bridge is provided by the company, is jdk provided by the standard api. This type of drive is for all practical 
  Jdbc odbc transmitted to the call, local call by the odbc database-driven code. (Local database-driven code is provided by the database vendor binary code for database operations, such as the oracle for windows in the oci dll files) 

  Jdbc-odbc Bridge 
|
  Odbc 
|
  Manufacturers DB Server database code ————— 

  (1) 

  As long as the local machine equipped with the relevant odbc driver then used jdbc-odbc Bridge can access almost all database-jdbc 
  Odbc method for the client already has odbc driver application or feasible, but because jdbc-odbc first call 
  Odbc odbc to calls by the local database interface to the database. Therefore, the implementation of relatively low efficiency, large volume of data access application is not appropriate. Moreover, this approach requires the client must be installed odbc driver, which is why the Based on 
  Internet, intranet application is not appropriate because you can not require all customers can find odbc driver. 

  Type 2: Api driven directly to the local api drive jdbc call into the standard database access the database again call this approach needs of the local database-driven code. 

  Driving local api 
|
  Manufacturers DB Server database code ————— 

  (B) 
  The drive than jdbc-odbc Bridge implementation efficiency has been greatly improved, but it remains to be loaded in the client database vendors to provide code base. This is not suitable for the internet-based application. Addition, he compared the efficiency of 3 , 4-jdbc-driven or is not high enough. 

  Type3: network protocol drivers that drive is really in line with our familiar with the establishment of the three-tier structure. Jdbc first of several requests for visits to the library passed to the server on the network middleware. Middleware server then request for translation Calling the standardized database, and then pass this call database server. middleware server is also used if the java a law, then in the middle layer can also use 1,2 - 
  Jdbc-driven process as a method of accessing database. 

  Network protocol driver ———– ———— Database Server middleware server 

  (Figure 3) 

  As a result of this drive is based on the server. Therefore, it does not need to load client database vendors to provide code base. Him and in the implementation of efficiency and scalability is relatively good because most functions are realized in the server end, drive can be designed so that a small, very fast loading into memory, but this drive in the middleware layer still need to have other database-driven configuration process, and because more than a middle layer transfer data, it is not the implementation of efficiency is the best. 

  Type4 local agreements directly to the driver that drives jdbc call into conformity with the relevant norms at the request of the database system. Drive due to 4 applications can be written in direct and database server communications. This type of drive to achieve entirely by the java, Implementation of the platform independence. 

  Local agreements Server database-driven ———– 

  (Figure 4) 

  As a result of this drive does not need to call first jdbc pass odbc or local database interface, or server in the middle layer. Therefore, the implementation of its efficiency is very high. Moreover, it is not required at the client or server side loading any the software or drivers. 
  This process can be driven by the dynamic download, but for different databases need to download different drivers. 

  The above four types of jdbc drives a note. Then they suitable for the type of application development? 
  Jdbc-odbc Bridge because of its low efficiency of the implementation of more suitable as a development and application of the excessive programmes, or the programming for beginners to understand jdbc also more applicable. 
  For those in need of large data applications operating procedures should be considered 2,3,4-driven. In intranet applications can be considered the type 2 driver, but due to 3,4-driven than in the implementation of the efficiency drive type 2 Fixed a clear advantage, and the current development trend is the use of pure java. 3,4 Therefore drive can also consider as a target. 
  As for the internet based on the application of 3,4-only consider the driver. Drive as 3 can have a variety of database-driven server configuration in the middle layer. Therefore, the most appropriate drive type that need to connect multiple different types of databases, 
  And the connection with the application of high demand. Four of those drives are suitable for connecting a single database application of the Working Group. 

  Having said that, it should be related jdbc driver where to download? Virtually all major database vendors 
  (Oracle, sybase, db2) on the multi-jdbc have had good support (Microsoft exceptions). You can go to their official site to download. 
  Microsoft has not developed due to the jdbc sqlserver drive, but with other vendors to provide drivers. Here to tell you recommend several sites 
  Http://www.idssoftware.com/jdbcdrv.html (3) 
  Http://www.jturbo.com/ (4) 
  Http://www.inetsoftware.de/ (4) 
  I particularly recommend the 2000-net Sprinta sqlserver drive because his driver only 47 K no time limit, and is 4 
  Drive. 

  For programming, how to use JDBC to connect, we do not introduced in detail. Readers can find in the jdk example, the directory for jdk / demo / jfc / dbdemos If you download other vendors drivers in compressed files will be there are examples. 
  If you call in the applet jdbc driver must pay attention to access the database web server and database server must be in the same machine, which is java applet security regulations required. 

  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

IBATIS step by step (1)

  Abstract: iBATIS step by step (1) 

  : Argan from the blog: http://www.matrix.org.cn/blog/wolfw/ 

  This time to write a step by step the step 1, first using one of the most simple examples to illustrate the flexibility and convenience iBATIS 

  Some of the explanations, 

  1. Examples of the use eclipse to develop, so there eclipse the annex of the bag. Classpath and. Project documents, in order to simple and clear, I try to simplify the relevant configuration 

  2. Annex with all the necessary jar and win2k and fedora core jdk1.4.2 + 1 + on the test pass jdk1.4.2 

  Below start …. 

  First set up a simple bean: Account 

  Private int id; 
  Private String firstName; 
  Private String lastName; 
  Private String emailAddress; 

  Getters & setters 

  Xml then write a paper, the configuration is the sql mapping, for example, called Account.xml 

  <? Xml version = "1.0" encoding = "UTF-8"> 

  Sql-map 
  PUBLIC "- / / iBATIS.com / / DTD SQL Map 1.0 / / EN" 
  "Http://www.ibatis.com/dtd/sql-map.dtd"> 


Hibernate development BLOG

  Abstract: hibernate development BLOG 

  : Development tools used MYECLIPS3.6, first of all, is to establish projects into STRUTS + HIBERNATE packets, and then configuration directory with the SRC hibernate.cfg.xml. MYSQL I use the database, so configuration is as follows: