Fusion instance resolution for SQL Server 2000 and JDBC

Source: Internet
Author: User
Tags odbc sql server driver


SQL Server 2000 is today's network programming in the use of more than a database system, while Java is a popular network programming language, in the network programming involved in more and more important is the database problem, Java itself provides a variety of mainstream database system support, By providing the java.sql library, provides a unified interface, so that you can in the Java environment do not have to make large-scale changes to the program, as long as the corresponding driver changes, you can achieve the operation of various databases, thereby improving the software lifecycle and reduce software development costs and maintenance costs, In this case, the integration of SQL Server 2000 and Java is more important, and this article briefly describes the integration of SQL Server 2000 and JDK.



System Requirements:



Database: SQL Server SP3



Driver: SQL Server driver for JDBC



Java version: jdk1.2 above



1, we first use the Jdbc-odbc Bridge to implement the database connection, this relatively simple, first use SQL Server Enterprise Management it to build a database test, and establish a simple table first_table ODBC data source, each step with the default action.



Write a simple test program that mainly implements the database connection, and a simple SQL operation, the code is as follows:


/***********************************************
/*
/*dbtest.java
/*
/******************************************* */
Import java.sql.*;
public class Dbtest
{

Connection con;
Statement STA;
ResultSet rs;

String driver;
String URL;
String user;
String pwd;
Public Dbtest ()
{
Driver = "Sun." JDBC.odbc.JDBCOdbcDriver ";
url = "JDBC:odbc:store_manager";
user = "Share";
PWD = "Share";
Init ();
}
public void Init ()
{
try{
Class.forName (driver);
System.out.println ("Driver is OK");
con = drivermanager.getconnection
(URL,USER,PWD);
System.out.println ("conection is OK");
STA = Con.createstatement ();
rs = Sta.executequery
("SELECT * from room");
while (Rs.next ())
System.out.println
(Rs.getint ("Roomnum"));
}catch (Exception e)
{
E.printstacktrace ();
}
}

public static void Main
(String args [])
Replace yourself []
{
New Dbtest ();
}
}
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.