The following is a basic summary of SQL APIs. For more information, see.
Public interface resultsetmetadata can be used to obtain the type and attribute information of columns in the resultset object. The following code snippets create the resultset object RS, create the resultsetmetadata object rsmd, use rsmd to find the number of RS columns, and whether the first column in the RS can be used in the WHERE clause.
Resultset rs = stmt.exe cutequery ("select a, B, c from Table2 ");
Resultsetmetadata rsmd = Rs. getmetadata ();
Int numberofcolumns = rsmd. getcolumncount ();
Boolean B = rsmd. issearchable (1 );
Drivermanager
Trace available drivers. The JDBC management layer acts between users and drivers
Public class statement extends object
The statement object indicates a basic statement, where a single method is applied to a target and a set of parameters to return results, such as "A. setfoo (B )". Note: This example uses a name to indicate the target and its parameters. The statement object does not require a namespace and can be constructed using the value itself. The statement object associates the specified method with its environment as a simple set of values: an array of targets and parameter values.
Public interface connection
Connection (session) to a specific database ). Execute the SQL statement in the connection context and return the result.
The database of the connection object can provide information to describe its table, supported SQL syntax, stored procedures, and the function of this connection. This information is obtained using the getmetadata method.
Note: by default, the connection object is in the automatic submission mode, which means that it will automatically submit changes after each statement is executed. If the automatic submission mode is disabled, the commit method must be explicitly called to submit changes; otherwise, the database changes cannot be saved.
The connection object created using the JDBC 2.1 core API has a type ing table that is initially null associated with it. You can enter a custom ing for the UDT in the ing table of this type. When the resultset. GetObject method is used to retrieve the UDT from the data source, the GetObject method checks the type ing table of the connection to check whether there are items that should be UDT. If yes, the GetObject method maps the UDT to the indicated class. If no value exists, the UDT is mapped using the standard ing relationship.
You can create a new type ing table, which is a Java. util. map object. You can create an item in it and pass the item to Java that can execute a custom ing relationship. SQL method. In this case, This method uses the given type ing table instead of the ing table associated with the connection.
For example, the following code snippet specifies that the SQL type athletes will be mapped to the athletes class in Java programming language. This code snippet gets the type ing table from the connection object con, inserts some items in it, and then sets the type ing table as the connected type ing table using the new items.
Java. util. Map map = con. gettypemap ();
Map. Put ("myschemaname. Athletes", class. forname ("athletes "));
Con. settypemap (MAP );
JDBC and ODBC drivers:
ODBC binary code and in many cases, the database client code must be installed on each client that uses the driver. If the client is installed on the network used by the program, it is not a big problem. This should be the absolute advantage of JDBC. In addition, the JDBC-ODBC bridge driver java. SQL. Drive Interface is implemented in Sun. JDBC. ODBC. jdbcodbcdriver. The jdbcodbc. dll file is supported in the java_home/bin directory.
Primary keys in the database table:
A table's primary key is composed of one or more fields. Its values are unique and null values are not allowed. The primary key uniquely identifies each record in the table.
Considerations for creating a database:
Database owner
Initial capacity, maximum capacity, and growth of the database
Path for storing database files
A database includes:
Table view Stored Procedure trigger
Public interface callablestatementextends preparedstatement
Interface used to execute SQL stored procedures. Jdbc api provides a Stored Procedure SQL escape syntax that allows all RDBMS to call stored procedures in a standard way. This escape syntax has a form that contains result parameters and a form that does not contain result parameters. If you use result parameters, you must register them as out parameters. Other parameters can be used for input, output, or both. Parameters are referenced in sequence by number. The first parameter is numbered 1.
{? = Call <procedure-Name> [<arg1>, <arg2>,...]}
{Call <procedure-Name> [<arg1>, <arg2>,...]}
The in parameter value is set using the set method inherited from preparedstatement. Before executing a stored procedure, you must register the types of all out parameters. Their values are retrieved using the get method provided by this class after execution.
Callablestatement can return a resultset object or multiple resultset objects. Multiple resultset objects are processed by operations inherited from statement.
To achieve maximum portability, The resultset object and the update count of a call should be processed before the value of the output parameter is obtained.
Usage of the preparedstatement object:
Preparedstatement inherits statement,
Preparedstatement is pre-compiled with high efficiency,
Preparedstatement can bind parameters to prevent SQL Injection problems.