Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package hitesh.sqlapp;
  2. import android.annotation.SuppressLint;
  3. import android.os.StrictMode;
  4. import android.util.Log;
  5. import java.sql.SQLException;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. /**
  9. * Created by h-pc on 16-Oct-15.
  10. */
  11. public class ConnectionClass {
  12.     String ip = "192.168.0.100";
  13.     String classs = "net.sourceforge.jtds.jdbc.Driver";
  14.     String db = "Andro";
  15.     String un = "hitesh";
  16.     String password = "789";
  17.  
  18.     @SuppressLint("NewApi")
  19.         public Connection CONN() {
  20.         StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  21.         StrictMode.setThreadPolicy(policy);
  22.         Connection conn = null;
  23.         String ConnURL = null;
  24.             try {
  25.             Class.forName(classs);
  26.             ConnURL = "jdbc:jtds:sqlserver://" + ip + ";" + "databaseName=" + db + ";user=" + un + ";password=" + password + ";";
  27.             conn = DriverManager.getConnection(ConnURL);
  28.                 } catch (SQLException se) {
  29.                                         Log.e("ERRO", se.getMessage());
  30.                                         } catch (ClassNotFoundException e) {
  31.                                         Log.e("ERRO", e.getMessage());
  32.                                         } catch (Exception e) {
  33.                                         Log.e("ERRO", e.getMessage());
  34.                                         }
  35.         return conn;
  36.         }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement