Implementing object-Oriented Programming with Java (8)

Source: Internet
Author: User

Jdbc

The query returns a result set object

Loop whether the result can be searched down
All of the following tables in JDBC are starting from 1
GetXXX (subscript) GetXXX (column name)

? Placeholder

public class Testsave

{
public static void Main (string[] args)

{
Connection conn = null;
Statement stmt = null;
try {
1. Load driver (Class)
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
2. Create a linked object
URL: The link address of the database localhost (IP address of 127.0.0.1 native)
User: The account name of the database
Password: password for the database
conn = Drivermanager.getconnection ("jdbc:sqlserver://localhost:1433;databasename=student", "sa", "OK");
Link to test database
SYSTEM.OUT.PRINTLN (conn);
3. Writing SQL statements
String sql = "INSERT into students values (3, ' xiaoming ', 22, ' Nanjing ')";
4. Execute SQL statements
Creating a Processing object (SQL)
stmt = Conn.createstatement ();
5. Processing the SQL Executeupdate method handles the addition of the Delete modification statement
The method return value is the number of rows affected
int i = stmt.executeupdate (sql);
System.out.println (i);
The resource needs to be closed after the call is completed
} catch (ClassNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} finally{
try {
if (stmt! = null)

{
Stmt.close ();
}
IF (conn! = null)

{
Conn.close ();
}
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
}

The Executeupdate method handles increasing the deletion of modified statements.

The method return value is the number of rows affected

Implementing object-Oriented Programming with Java (8)

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.