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)