Original: Structure function in the application of Java
Original: Structure function in the application of Java
As recent project, we need to. Net to the development of a project to Java, which uses Java in the structure function, now, it said that the use of concrete.
First a new Java class named: structure.java
Definition of a structure:
(Class DBUserXX
? String DLName = "";
? String TrueName = "";
? String Jh = "";???
?)
New pay structure to the function of:
Public DBUserXX GetUserXX () throws Exception (
?? DBUserXX dbUserXX = new DBUserXX ();
?? DbUserXX.DLName =? "Dlname";
?? DbUserXX.TrueName = "Truename";
?? DbUserXX.Jh =???" jh ";
? Return dbUserXX;
?)
Testing of the new main () function.
Public static void main (String args []) throws Exception
? (
?? DBUserXX? E = new DBUserXX ();
?? System.out.println ( "DLName =" + + e.DLName "TrueName =" + + e.TrueName "Jh =" + e.Jh);
?)
This completed the test.
Now we come to talk about the use of more complex.
Assume that now need to pay more of the structure of the group values, then we need to speak the above methods expansion needed for a ArrayList.
Expansion GetUserXX () function:
Public List GetUserXX () throws Exception (
????? String sql = "select dlname, Truename, jh from UserXX";
????? OracleConnection oc = new OracleConnection ();
????? Oc.open ();
????? ResultSet rs = oc.executeSelect (sql);
????? List list = new ArrayList ();
????? While (rs.next ()) (
???????? DBUserXX dbUserXX = new DBUserXX ();
???????? DbUserXX.DLName =?? Rs.getString ( "dlname");
???????? DbUserXX.TrueName =? Rs.getString ( "Truename");
???????? DbUserXX.Jh =? Rs.getString ( "jh ");???
???????? List.add (dbUserXX);
??????}
????? Rs.close ();
????? Return list;
)
This GetUserXX () return value on DBUserXX contains multiple types of structure of the (on the database connectivity in this small stresses, there are many on-line information in this regard).
The DBUserXX ():
Laws main ():
Public void main (String args []) throws Exception
? (
? System.out.println ( "Start ………");
? GetUserXX List list = ();
? For (int i = 0; i <list.size (); i + +) (
??????? DBUserXX e = (DBUserXX) list.get (i);
??????? System.out.println ( "DLName =" + + e.DLName "TrueName =" + + e.TrueName "Jh =" + e.Jh);
????}
?? System.out.println ( "End ………");
?)
So that it could be tested.
End!
Posted on 2006-04-03 18:54 HHJ reading (878) Comments (1) edit collections cited
Tags: function






