// 准备数据库驱动程序 String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载数据库驱动程序 Class.forName(driver); // 准备连接参数 String connectionUrl = "jdbc:sqlserver://localhost:1433;"; String user = "xxx"; String password = "xxx"; // 创建数据库连接 Connection connection = null; connection = DriverManager.getConnection(connectionUrl, user, password); // Statement statement = null; statement = connection.createStatement(); String sql = "SELECT * FROM YourTable;"; // 获取查询结果 ResultSet resultSet = null; resultSet = statement.executeQuery(sql); // 处理结果集 while(resultSet.next()){ } // 释放SQL资源,关闭连接 resultSet.close(); statement.close(); connection.close();
时间: 2024-10-11 07:03:59