/** * Function: Demo using JDBC-ODBC bridge connection to manipulate SQL database * Xu Shouwei * Operation steps: * 1. Configure Data source * 2. Connect data source in program * 3. Operation data */package com.jasxu; Introduction of SQL packet import java.sql.*; public class T1 {
/** * @param args */public static void main (string[] args) {//TODO auto-generated method stub Connection Ct=nu ll Statement St=null; try {//1. Load driver (role: Add the required driver
Memory) Class.forName
("Sun.jdbc.odbc.JdbcodbcDriver"); 2. Get Connected (specify which data source to connect to, the user
Name and password) ct=drivermanager.getconnection
("Jdbc:odbc:Jasxu", "sa", "Xushouwei"); 3. The use of creating statement or PreparedStatement//statement is to send SQL statements to the database st=ct.createstatement (); 4. Execute (crud, create DATABASE, back up database,
Delete data)//For example: Demo adds a piece of data to the Dept Table//executeupdate can perform cud (add, Delete,
Modify) operation int I=st.executeupdate ("INSERT INTO
Dept VALUES (' 50 ', ' Security Department ', ' Suqian ') "); if (i==1) {System.out.println ("data is added as
Work! "); } else {System.out.println ("Data add missing
Defeat! "); }} catch (Exception e) {//Todo:handle Exception e.printstacktrace (); } finally {//close the resource, close the order (who created the creator first to close) try {//for the program to be more robust if (St!=null) {st.close (); } if (Ct!=null) {ct.close (); }} catch (Exception E2) {//Todo:handle Exception e2.printstacktrace (); } }
}
}