Created
March 2, 2020 17:34
-
-
Save brunopk/ca89a4b572b5169a62849a24bfd503e0 to your computer and use it in GitHub Desktop.
SQL Server connection with Java 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
public class Main { | |
public static void main(String[] args) { | |
// Create a variable for the connection string. | |
String connectionUrl = "jdbc:sqlserver://10.64.36.137:1433;user=sigma;password=Password33"; | |
try { | |
Connection con = DriverManager.getConnection(connectionUrl); Statement stmt = con.createStatement(); | |
String SQL = "SELECT TOP 10 * FROM Visa"; | |
ResultSet rs = stmt.executeQuery(SQL); | |
// Iterate through the data in the result set and display it. | |
while (rs.next()) { | |
System.out.println(rs.getString("Nombre") + " " + rs.getString("Apellido")); | |
} | |
} | |
// Handle any errors that may have occurred. | |
catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment