Java Connection SQL server2008 database configuration _mssql

Source: Internet
Author: User
Tags microsoft sql server odbc microsoft website

1. First to go to the Microsoft website download sqljdbc2.0 driver--microsoft sql Server JDBC Driver 2.0.exe, very small about 4 m, after decompression, there are 2 jar packages, Sqljdbc4.jar and Sqljdbc.jar, the two are the same, just for your JDK version of the different, if you are JDK6.0 Direct import Sqljdbc4.jar, the following version of the import Sqljdbc.jar, if you are afraid of trouble, two of them will lead in the line.

2. Package Guide is finished, now start the SQL Configurator, SQL2000 's default port is 1433, so as long as the port can be connected, but 08 of the port is said to be dynamic, the specific I also do not know, because this port I was also the whole 2 days, finally connected.
To open a configuration device:

The TCP dynamic port (default 1163) for IP all is changed to 1433, and does not change, because most people are accustomed to using the default 1433, the IP2 has enabled the selection-yes, OK.

The same method, open the client TCP/IP, the port is also 1443, as shown in the figure:

Then enter the test in the DOS command telnet 127.0.0.1 1433,
If the result has only one cursor flashing, it means that the 127.0.0.1 1433 port is already open.
If the connection host port 1433 is not open, long to change the port.

ODBC to establish a data source

1 Accessing SQL Server2000 databases with Java applications

(1) Establishing a database

Start Microsoft SQL Server2000, open Enterprise Manager to create a database named Student management system in database, and under it, create a datasheet called Student information, as shown in Figure 1.

(2) establishing (ODBC) data sources and drivers

Open the ODBC Data Source Administrator dialog box on the control panel through the data Source (ODBC) of Administrative Tools. Click the System DSN tab, and then click the Add button to get the Create Data Source dialog box, select SQL Server and click Finish to the Create a new data source to the data source name item in the SQL Server dialog box fill in "Madata" and choose "Server Name". Then click the Next button, select the Windows NT Authentication with network logon ID project, click Next, and change the default database to MyData, click Next, click Finish, and then click Test Data Source, and then click OK to complete the (ODBC) data source and driver setup.

(3) Writing Java programs

Package com.test1;
Import java.util.*;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Import java.sql.*;
public class Test extends jframe{JPanel jp1,jp2;
JLabel jl1;
JButton jb1,jb2,jb3,jb4;
JTable Jt=null;
JScrollPane Jsp=null;
JTextField JTF;
PreparedStatement Ps=null;
Connection Ct=null;
ResultSet Rs=null; 
Vector Rowdata,columname; public static void Main (String args[]) {test test=new Test ();} public test () {jp1=new JPanel (); Jl1=new JLabel ("Please enter first Name:"
);
Jtf=new JTextField (10); 
Jb1=new JButton ("query:");
Jp1.add (JL1);
Jp1.add (JTF);
Jp1.add (JB1);
Jp2=new JPanel ();
Jb2=new JButton ("add:");
Jb3=new JButton ("Modify:");
Jb4=new JButton ("delete:");
Jp2.add (JB2);
Jp2.add (JB3);
Jp2.add (JB4);
Columname = new Vector ();
Columname.add ("School Number");
Columname.add ("name");
Columname.add ("class");
Columname.add ("fasten");
Columname.add ("Age");
Columname.add ("gender");
Columname.add ("Native Place");
RowData =new Vector (); try {class.forname ("Sun.jdbc.odbc.JdbcOdbcDriver"); Ct=drivermanager.getconnection ("Jdbc:odbc:myData ");
Ps=ct.preparestatement ("Select *from Student Information");
Rs=ps.executequery (); while (Rs.next ()) {vector hang=new vector (); Hang.add (rs.getstring (1)); Hang.add (Rs.getstring (2)); Hang.add (
Rs.getstring (3));
Hang.add (Rs.getstring (4));
Hang.add (Rs.getint (5));
Hang.add (rs.getstring (6)); 
Hang.add (rs.getstring (7));
Rowdata.add (hang);
(Exception e) {System.out.println ("Database load failed!");} finally {} System.out.println ("Database load succeeded!");
Jt=new JTable (rowdata,columname);
Jsp=new JScrollPane (JT);
This.add (JP1, "North");
This.add (JSP);
This.add (JP2, "South");
This.setsize (400,300);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.setvisible (TRUE); }
}

Note that you are introducing a Jar Pack SQLJDBC 2.0

Java Connection SQL2008-timesong-How many flowers fall in the dream

Let's get to the point.

Open SQL2008 Enterprise Manager

Execute SQL statement

Use Mydb
go
SELECT * TABLE1

The results are:

Description The SQL has been successfully connected and the table is created in the database MyDB TABLE1

Thank you! Where is the wrong place to go to which readers point out and learn from each other

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.