Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.lenovo.testing1;
- import android.annotation.SuppressLint;
- import android.os.StrictMode;
- import android.util.Log;
- import java.sql.*;
- public class ConnectionClass {
- String hostName = "haozailai.database.windows.net";
- String dbName = "haozailai";
- String user = "username";
- String password = "password";
- @SuppressLint("NewApi")
- public Connection CONN() {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- String ConnURL;
- Connection conn = null;
- try {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- String url = String.format("jdbc:jtds:sqlserver://haozailai.database.windows.net:1433;database=haozailai;user=username;password=password;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;");
- conn = DriverManager.getConnection(url);
- }catch (SQLException se)
- {
- Log.e("error here 1 : ", se.getMessage());
- }
- catch (ClassNotFoundException e)
- {
- Log.e("error here 2 : ", e.getMessage());
- }
- catch (Exception e)
- {
- Log.e("error here 3 : ", e.getMessage());
- }
- return conn;
- }
- }
Add Comment
Please, Sign In to add comment