Java Connection SQL Server code snippet

Source: Internet
Author: User

A recent need to verify the "Android Terminal" Download data efficiency issues, which need to add test data to the SQLSERVER2008 database

Step1: Defining related Database Information

Static final String DRIVER = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; static final String URL = "jdbc:sqlserver:// 192.168.0.249\\sql2008;databasename=lzrfid "; static final string USER =" sa "; static final String PWD =" 1 ";

Step2: Getting SQL connections

        /** *  * Get SQL Connection * @return * @author * @since  1.0.0 */public static Connection getconnection () {Connection con = nu ll;try {class.forname (DRIVER); con = drivermanager.getconnection (URL, user,pwd);} catch (ClassNotFoundException e) { E.printstacktrace ();} catch (SQLException e) {e.printstacktrace ();} return con;}

Step3: A simple operational database

    Statement Statement;    Connection Connection;    Connection = getconnection ();    statement = Connection.createstatement ();
String sql = "SELECT * From ...";
Statement.execute (SQL);

The above is just the simplest connection operation, here to save, easy to consult later

Java Connection SQL Server code snippet

Related Article

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.