JDBC learning notes (3)
Thinkersky [yanghuangming@rongji.com]
Amber dusk in a very beautiful distant your face did not make it installed. I am crazy. I miss the shadow. I have been drawn together in the evening. I am in my hands. I have a meal. I have a sheep mint. Your temperament is pumped with the face. It is very transparent in the morning. I like to be seen in the booth. I have quietly appeared on your side. I smile and enjoy the sun. I just want you. Umbrella, you are afraid of your shoulders, I am afraid for forgotten because of the fans of fish, we start talking to the topic, the topic will continue to play, you will never play the balloon, I will take you, I will talk to you. Blind cakes with your mouth jam I want to try the garden game videos to play this world together
This is the lyrics of my favorite song "Garden Garden" in Jaylun's "Seven Miles". The whole song is ashamed, and whenever I listen to this song, it always Can cause my infinite thoughts. The thoughts are like Tiantao, bringing me back to that pure first love, let me often immerse in the happiness of love. Full of love, I am grateful, let us bless the world with lovers.
A few days ago, let me know a general understanding of JSP access to the database management system through JDBC. Today, some more complicated applications of JDBC will be understood.
First, understand the information of the database via the DatabaseMetadata object
After connecting the database management system through JDBC, you get a Connection object, which can get various information about the database management system from this object, including each table in the database, each column, data type, trigger, storage Process and other information. Based on this information, JDBC can access a database that implements prior understanding. Getting this information is implemented on an object of the DatabaseMetadata class, while the DatabaseMetadata object is available on the Connection object.
According to the practice, let's take a look at the following example:
Package com.rongji.deemo;
Import java.sql.connection;
Import java.sql.driverManager;
Import java.sql.statement;
Import java.sql.databaseMetadata;
Public class dataconn {
Public dataconn () {
}
Public static void main (String [] args) {
Try
{
// Load the driver
// The following code is to load the JDBD-ODBC driver
Class.Forname ("Oracle.jdbc.driver.OracleDriver");
//establish connection
// Connect to DBMS with the 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 User = "ums";
String password = "rongji";
// Create a connection with URL
Connection con = DRIVERMANAGER.GETCONNECTION (URL, User, Password);
/ / Get information about the database
Databasemetadata dbmetadata = con.getMetadata ();
/ / Return a String class object, representing the URL of the database
System.out.println ("URL:" DBMetadata.getURL () ";");
/ / Returns the username of the current database management system.
System.out.println ("UserName:" DBMetadata.getuserName () ";"); // Returns a Boolean value indicating whether the database only allows a read operation.
System.out.println ("IsreadOnly:" DBMetadata.isreadOnly () ";");
/ / Return to the product name of the database.
System.out.println ("DatabaseProductName:" DBMetAdata.getDatabaseProductName () ";");
/ / Return to the version number of the database.
System.out.println ("DatabaseProductVersion:" DBMetadata.GetDatabaseProductVersion () ";");
// Returns the name of the drive driver.
System.out.println ("Drivername:" DBMetadata.getdrivername () ";");
// Return to the version number of the driver.
System.out.println ("driverversion:" dbmetadata.getdriverversion ());
// Close connection
C. close ();
}
Catch (Exception E)
{
// Output exception information
System.err.println ("SQLException:" E.GetMessage ());
E.PrintStackTrace ();
}
}
}
Through the example above, we can see that the implementation of the object of the DatabaseMetadata class, as the following statement
<%
DatabaseMetadata DataMeta = con.getMetadata ();
%>
A number of methods for obtaining a data source are available in a very detailed understanding of the database in a DatabaseMetadata class. Just as the information displayed in our above example [Other methods, please refer to the DatabaseMetadata class in the JDK API]:
GetURL ()
Returns a String class object that represents the URL of the database.
Getusername ()
Returns the username of the current database management system.
IsreadOnly ()
Returns a Boolean value indicating whether the database only allows read operations.
GetDatabaseProductName ()
Returns the product name of the database.
GetDatabaseProductVersion ()
Returns the version number of the database.
GetDrivername ()
Returns the name of the drive driver.
GetDriverversion ()
Returns the version number of the driver.
OK, I will learn this today, this weekend is a bit long, because I miss her.