Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getDatabase() {
- String connectionString = "";
- connectionString = "jdbc:sqlserver://semicoloniv.database.windows.net:1433;database=Data;user=SemicolonIV@semicoloniv;password=Semicolon04;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
- // Declare the JDBC objects.
- Connection connection = null;
- Statement statement = null;
- ResultSet resultSet = null;
- PreparedStatement prepsInsertPerson = null;
- PreparedStatement prepsUpdateAge = null;
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- } catch (ClassNotFoundException e) {
- Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
- e.printStackTrace();
- }
- try {
- connection = DriverManager.getConnection(connectionString);
- return "Connected";
- } catch (Exception e) {
- Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
- e.printStackTrace();
- } finally {
- // Close the connections after the data has been handled.
- if (prepsInsertPerson != null) try {
- prepsInsertPerson.close();
- } catch (Exception e) {
- }
- if (prepsUpdateAge != null) try {
- prepsUpdateAge.close();
- } catch (Exception e) {
- }
- if (resultSet != null) try {
- resultSet.close();
- } catch (Exception e) {
- }
- if (statement != null) try {
- statement.close();
- } catch (Exception e) {
- }
- if (connection != null) try {
- connection.close();
- } catch (Exception e) {
- }
- }
- return "Not Connected";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement