JDBC-ODBC Bridge connection mode manipulating SQL database

Source: Internet
Author: User

/** * 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 (); }   }

}

}

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.