Java
Java
Java
1. Java
2.
2.1
SQL ServerWindowsSQL Server 2008
2.1.1 windows
2.1.2 SQLServer2005Express
2.1.3 sasa
sasasa
2.1.4
2.1.5
SQL Server
2.2 TCPIP
1
2 SQLEXPRESS TCPIP
3,IPIP allTCP1433netstat
4SQLEXPRESS
1
sqlserversqljdbc4.jar, Configure Build Path
sqljdbc4.jar
2.
studentstudentInfoidsno snamesql
create database student
use student
create table studentInfo
id int identity1,1 primary key,
sno varchar10 not null unique,
sname varchar30 not null
insert into studentInfo values17001,
select from studentInfo
Main
import java.sql.;
public class Main
public static void mainString args
String driverNamecom.microsoft.sqlserver.jdbc.SQLServerDriver;
String dbURLjdbc:sqlserver:localhost:1433;DatabaseNamestudent;
String userNamesa;
String userPwd123;
Connection dbConnnull;
PreparedStatement psnull;
ResultSet rsnull;
try
Class.forNamedriverName;
dbConnDriverManager.getConnectiondbURL,userName,userPwd;
String sqlselect from studentInfo;
SQLPreparedStatementStatement
psdbConn.prepareStatementsql;
PreparedStatement StatementexecuteQuerysql
ResultSet.next,.,
next ,.next.
rs ps.executeQuery;
while rs.next
int idrs.getIntid;id
String studentidrs.getStringsno;studentid
String namers.getStringsname;name
System.out.printlnidid studentidstudentid namename;
catchException e
e.printStackTrace;
System.out.print;
finally
,,,.
try
rs.close;
ps.close;
dbConn.close;
catch SQLException e
TODO Autogenerated catch block
e.printStackTrace;