源码
连接到数据库出现了问题,源代码如下
package com.yyxx.day17;
import java.sql.*;
public class Jdbc {
public static void main(String[] args) throws SQLException {
Connection ct=null;
Statement sm=null;
ResultSet rs=null;
try {
String url = "jdbc:microsoft:sqlserver://localhost:1433:DatabaseName=spdb";
// 连接数据库-forName:返回与带有给定字符串名的类或接口相关联的 Class 对象
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 得到连接-getConnection:建立到给定数据库 URL 的连接
ct = DriverManager.getConnection(url,
"sa", "");
// 创建Statement-将 SQL 语句发送到数据库
sm = ct.createStatement();
rs = sm.executeQuery("select * from users");
} catch (ClassNotFoundException e) {
// TODO: handle exception