Java连接sqlserver的程序

package com.ytu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {

	public static void main(String[] args) {
		  
		  String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=student"; 
		  String user = "sa"; 
		  String password = "123456"; 
		  try {
			  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			  Connection conn = DriverManager.getConnection(url,user,password);
			  Statement stmt = conn.createStatement();
			  ResultSet rs = stmt.executeQuery("select * from info");
			  while(rs.next()) {
				  System.out.println(rs.getString(3));
			  }	
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("Error Happened");
		}
	}
}

上一篇:『每日一题 2012-02-13』整数划分问题


下一篇:VC6集成环境编辑器字体的修改