Function: Read the data in the database to the java cube class and calculate the cube size. 1. Use PLSQLDevelopor to design a Table named first; Table-gt
Function: Read the data in the database to the java cube class and calculate the cube size. 1. Use PL/SQL Developor to design a Table named first; Table-gt
Function: Read the data in the database to the java cube class and calculate the cube size.
1. Use PL/SQL Developor to design a table named first;
Table-> new Table: design the tablespace, the size of the field, and the primary key;
Table-> first-> edit data: Enter the required data, and a Table is generated.
2. Use java code to access the Oracle database. The Code is as follows:
Import java. SQL .*;
Import java. SQL. ResultSet;
Import java. SQL. SQLException;
Import java. util. Vector;
Public class Test {
Static Vector CubeObjects = new Vector ();
Public static void main (String [] args) throws ClassNotFoundException, SQLException {
String driver = "oracle. jdbc. driver. OracleDriver ";
String strUrl = "jdbc: oracle: thin: @ a9ae3e7c1051465: 1521: idpdb"; // idpdb indicates the database name.
Connection conn = null;
ResultSet rsResult = null;
Statement stmt = null;
Class. forName (driver );
// The second parameter is the database user name, and the third parameter is the database password.
Conn = DriverManager. getConnection (strUrl, "idp_pub_m", "idpapp ");
Stmt = conn. createStatement ();
RsResult=stmt.exe cuteQuery ("select * from first ");
While (rsResult. next ()){
Cube cub = new Cube (rsResult. getInt (1), rsResult. getInt (2), rsResult. getInt (3), rsResult. getInt (4 ));
CubeObjects. add (cub );
}
Int I = 0;
For (Cube cube: CubeObjects ){
System. out. println ("rectangular order" ++ I + ":" + calculate (cube ));
}
}
Static int calculate (Cube cube ){
Try {
If (cube. Height = cube. Length & cube. Length = cube. Width ){
Return cube. Height * cube. Length * cube. Width;
} Else {
Throw new Exception ("not cube ");
}
} Catch (Exception e ){
System. out. println (e. getMessage ());
}
Return 0;
}
}
Class Cube {
Int ID = 0;
Int Length = 0;
Int Width = 0;
Int Height = 0;
Public Cube (int ID, int Length, int Width, int Height ){
This. ID = ID;
This. Length = Length;
This. Width = Width;
This. Height = Height;
}
}