java连接sql server 2008

时间:2021-12-11 04:28:36

导入JDBC

import java.sql.SQLException;
public class text {
    public static void main(){
        Connection conn;
        Statement stmt;
        ResultSet rs;
        String url = "jdbc:sqlserver://localhost:1433;DatabaseName=我的数据库;";
        String sql = "select * from address_list where "+s2+"=('"+s1+"')";     
        try {
            conn = DriverManager.getConnection(url, "sa", "123456");
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            conn.close();
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}