Java database connection steps
1. Open the connection
2. Create a statement set: a normal statement set and a predefined statement set
Statement stat = conn. createStatement ();
PreparedStatement priceUpdateStmt =
Conn. prepareStatement ("SQL statement with question mark ");
PriceUpdateStmt. setString (1, in. nextLine ());
3. Execute the statement
Execteupdate () is used for DELETE, UPDATE, and INSERT operations ()
ExecuteUpdate returns an integer number, indicating the number of rows affected during deletion, update, and insertion.
ExecuteQuery () when selecting ()
The ResultSet is generated only after the executeQuery () method.
ResultSet indicates the content of several rows returned after Select.
The ResultSet calls the next method to return a row.
While (rs. next ())
{
Result. append (rs. getString (1 ));
Result. append (",");
Result. append (rs. getString (2 ));
Result. append ("\ n ");
}
NAME
AGE
AAA
33
BBB
55 rs
4. Disable the statement set
5. Disable the result set.
6. Close the connection
Metadata
ResultSet result = stat. getResultSet ();
ResultSetMetaData metaData = result. getMetaData ();
Int columnCount = metaData. getColumnCount ();
System. out. print (metaData. getColumnLabel (1 ));
This article permanently updates the link address: