java 连接 sqlserver

1.下载jdbc:Download - JDBC Driver for SQL Server | Microsoft Docs

2.提取jdbc的内容:

java 连接 sqlserver

 

 3.导入jar包到eclipse

java 连接 sqlserver

 

 java 连接 sqlserver

 

 

输入代码,运行:

 

 

 

package test;

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

public class cc {

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		// TODO Auto-generated method stub
		
		
		 
	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=AA;user=sa;password=123456;"; Connection conn = DriverManager.getConnection(connectionUrl); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM test"); //如果有数据,rs.next()返回true while(rs.next()){ System.out.println(rs.getString("ID")+" 年龄:"+rs.getInt("value")); } } }

  

上一篇:XOR加密


下一篇:华为RS认证学习笔记1 企业的网络架构