JDBC learning notes (six)
Thinkersky [email: yanghuangming@rongji.com]
About marriage and love, a group of 5- 10 years old American children give their answers. Maybe it's stupid, but who can say that the little doll is not sensible?
1. How old is the right marriage age?
84 years old. At that time, I don't have to do anything, I have a lot of time. (Judi, 5 years old)
When I read the kindergarten, I have to take into account my wife. (Tommy, 5 years old)
2. What happened?
I listen to people say that this is related to the taste of your body. Adults like to use perfume. (Jane, 9 years old)
I think it will be shot in the east and west of an arrow - should not hurt. (Harlan, 9 years old)
3. What is the feeling of falling in love with a person?
If you are like learning to spell, I don't want to try it. Too much time. (Rio, 7 years old)
4. Is the appearance important?
The appearance is not the most important. I have a good time, but I have never heard who wants to marry me. (Gary, 7 years old)
5. Why do people always hold hands?
It's afraid of the ring! Those things are very expensive. (David, 8 years old)
6. Willing to love?
I still hope that I am in love with people - as long as I don't put "cat and mouse" (American popular cartoon). (Anneta, 6 years old)
Even if you want to hide, love will definitely find you - from 5 years old, I often want to hide it, but those girls can always find me. (Bobby, 8 years old)
7. How to let others fall in love with you?
Tell her that you have a lot of sugar. (Anguo, 9 years old)
8. How do you judge that two adults eat in the restaurant?
See who is paying. Men who loves love is willing to pay. (John, 9 years old)
People who love love always stare at you, you are staring at me, something you eat is cold. (Brad, 8 years old)
The person who loves love is dessert - they are quasi-sweet. (Christen, 9 years old)
9. When a person says "I love you", what is the heart thinking?
She is not allowed to be imagined: love is love, but it is best to take a bath at least one day. (Michelle, 9 years old)
10. When should I kiss my favorite people?
Unless I have enough money, I bought a wedding ring and a camera, otherwise I won't kiss a girl. Because the girls always want to record their marriage. (Jim, 10 years old)
11. How can love last?
Spend more, don't always think about work. (Tom, 7 years old)
Don't forget her name - it will be messy. (Roger, 8 years old)
It is very useful to kissing - even if you forget to clean up the garbage, she will forgive you. (Langdi, 8 years old)
Look at these, what do you think? Everyone has to experience the death of the old disease, and love is the most splendid embellishment on the ordinary life road. It is hard to imagine that there is no love, what is the human beings?
OK, the words home, today we continue to learn the previous stage.
First, processes the result set through the ResultSet object
From the previous study, we have mastered the SQL statement through the Statement class and its subclasses, and access the database management system. In general, most of the operation of the database is a query statement. The result of this statement is to return a RESULTSET class. To return the results of the query to the user, you must do the ResultSet object. Today, we will learn how to process the results set.
According to the practice, let's take a look at an example:
Package com.rongji.deemo;
Import java.sql. *; public class datamedemo {
Public DataDemo () {
}
Public static void main (String [] args) {
Try {
Class.Forname ("Oracle.jdbc.driver.OracleDriver");
//establish connection
// Second step is to connect to DBMS with an appropriate driver, look at the following code [You can modify the database related information you are connected]:
String Url = "JDBC: Oracle: Thin: @ 192.168.4.45: 1521: Oemrep";
String Username = "ums";
String password = "rongji";
// Create a connection with URL
Connection Con = DriverManager.getConnection (URL, UserName, Password);
Statement Sta = con.createstatement ();
String SQL = "SELECT * from RBAC_Application";
ResultSet ResultSet = Sta.executeQuery (SQL);
While (resultSet.next ()) {
INT INT_VALUE = ResultSet.Getint (1);
String string_value = resultSet.getstring (2);
String a = resultset.getstring (3);
String b = resultSet.getstring (4);
// Net data from the database in two different ways.
System.out.println (int_value "" string_value " a " " " "
b);
// The search result is output on the user browser.
}
// Get the result set information
ResultSetMetadata ResultSetMD = ResultSet.getMetAdata ();
System.out.println ("ColumnCount:" ResultSetMd.getColumnCount ());
For (int i = 1; i System.out.println ("ColumnName:" ResultSetMd.getColumnName (i) " "ColumnTypename:" ResultSetMd.getColumnPename (i)); System.out.println ("IsreadOnly:" ResultSetMd.isreadOnly (i) "Iswriteable:" ResultSetMd.iswritable (i) "Isnullable:" ResultSetMd.isnullable (i)); System.out.println ("TableName:" ResultSetMd.gettablename (i)); } //shut down C. close (); } Catch (Exception EX) { EX.PrintStackTrace (); } } 1, the basic processing method of the ResultSet class A RESULTSET object corresponds to a table returned by the query statement, contains all the query results, in fact, we can see a resultset object as a table. The processing of the ResultSet object must be performed progressively, and each column in each row can be processed in any order. The ResultSet object maintains a pointer to the current row. Initially, this pointer points to the first line. The NEXT () method of the Result class makes this pointer down. Therefore, the first time the next () method will guide the pointer to the first line of the result set, and the data of the first row can be processed. After processing, use the next () method to move the pointer down and continue to process the second line of data. The return value of the next () method is a Boolean type value, which is true, and the description has a next record, and the pointer has successfully pointed to the record, and it can be processed; if the return value is false, then Explain that there is no record, the result set has been processed. When processing each line, each column can be processed in any order. However, the processing can be processed on each column from left to right to obtain higher execution efficiency. The getxxx () method of the ResultSet class can get the search result from a column. Where XXX is a Java data type in JDBC, such as int, string, date, etc., which is similar to the PreparedStateMent class and the CallableStatement class setting SQL statement parameter value. The Getxxx () API provided by Sun provides two ways to specify the column name for retrieval: one is an index of a column with an int value, and the other is to index as a column name as a column name. You can refer to the above example. 2, get information about the result set Under the premise of the table structure of the database already understand, you can know some of the columns of the columns in the column of the columns, such as column name data type, and more. Sometimes don't know the results of the results concentrated, you can use the GetMetadata method of the ResultSet class to get the information set. As with the example above: ResultSetMetadata ResultSetMD = ResultSet.getMetAdata (); GetMetadata () method returns an object of a RESULTSETMETADATA class, using this class, get a lot of information about the result set, and give several common methods below: (1) getColumnCount () Returns an int value and points to the number of columns in the result set. (2) GetTableName (int column) returns a string that points out the name of the table represented in the parameter. (3) GetColumnLabel (int Column) returns a String object that is the display title of the column referred to in Column. (4) GetColumnName (int Column) returns the name of the column in the database. The String object returned by this method can be used as a parameter of the getxxx () method of the ResultSet class. However, there is no great practical meaning. (5) getColumnType (int coMLUMN) Returns the SQL data type of the specified column. His return value is an INT value. There is a definition of various SQL data types in the Java.sql.Types class. (6) getColumnTypename (int coMLUMN) Returns the name of the data type of the specified column in the data source. His return value is a String object. (7) IsReadonly (int column) Returns a boolean value indicating whether the column is read-only. (8) IsWriteable (int column) Returns a boolean value indicating whether the column can be written. (9) Isnullable (int column) Returns a Boolean value indicating whether the column allows you to deposit a NULL value. Well, today's study is here to tell a paragraph. 8.