Connect to an msql statement using JDBC

Source: Internet
Author: User
Connect to an msql statement using JDBC

1. // load the drive and call Java. lang. the forname method of the class to pass the name of the JDBC driver to be loaded. during runtime, the Class Loader locates and loads the JDBC driver class from the classpath environment variable. after the JDBC Driver Class is loaded. an instance of the driver class needs to be registered. class. forname ("com. microsoft. JDBC. sqlserver. sqlserverdriver "); 2. // call Java. SQL. drivermanager. the getconnection static method obtains the database connection and returns a java. SQL. connection object connection conn = drivermanager. getconnection ("JDBC: Microsoft: sqlserver: // localhost: 1433;" +
"Databasename = login", "sa", "123456 ");
3. // create a statement call the createstatement () method of the connection object to create a statement object. Statement stmt = conn. createstatement (); 4. // define an SQL statement
String SQL = "SQL statement"; 5. // use the statement object to execute the SQL statement resultset rs1_stmt.exe cutequery (SQL ); java.sqlPackage content

java.sqlThe package contains APIs for the following purposes:

  • PassDriverManagerThe utility establishes a connection to the database.

    • DriverManagerClass: establish a connection with the driver
    • SQLPermissionClass: When the code runs in Security Manager (such as applet ),DriverManagerSet a record stream
    • DriverInterface: provides APIs for registering and connecting drivers based on the JDBC technology ("JDBC driver ").DriverManagerClass usage
    • DriverPropertyInfoClass: Provides the attributes of the JDBC driver, not for general users.
  • Send SQL statements to the database
    • Statement: Used to send basic SQL statements
    • PreparedStatement: Used to send prepared statements or basic SQL statements (derived fromStatement)
    • CallableStatement: Used to call database stored procedures (derived fromPreparedStatement)
    • ConnectionInterface: provides methods to create statements and manage connections and their attributes.
    • Savepoint: Provides storage points in transactions.
  • Search and update query results
    • ResultSetInterface
  • Standard ing between classes and interfaces of SQL to Java programming languages
    • ArrayInterface: SQLARRAYIng relationship
    • BlobInterface: SQLBLOBIng relationship
    • ClobInterface: SQLCLOBIng relationship
    • DateClass: SQLDATEIng relationship
    • RefInterface: SQLREFIng relationship
    • StructInterface: SQLSTRUCTIng relationship
    • TimeClass: SQLTIMEIng relationship
    • TimestampClass: SQLTIMESTAMPIng relationship
    • TypesClass: Provides constants for the SQL type.
  • Custom ing SQL user-defined type (UDT) to classes in Java programming language
    • SQLDataInterface: Specifies the ing between a UDT instance and an instance of this type.
    • SQLInputInterface: provides a method to read the UDT attribute from the stream.
    • SQLOutputInterface: provides a method for writing the UDT attribute back.
  • Metadata
    • DatabaseMetaDataInterface: Provide information about the database
    • ResultSetMetaDataInterface: provides relatedResultSetObject column information
    • ParameterMetaDataInterface: provides relatedPreparedStatementCommand Parameter Information
  • Exception
    • SQLException: Throws are thrown by most methods when data access fails, and by other methods for other reasons.
    • SQLWarning: Throw to indicate a warning
    • DataTruncation: Throws to indicate that the data may have been truncated.
    • BatchUpdateException: It is thrown to indicate that not all commands in batch update are successfully executed.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.