Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.user.hello;
- import android.annotation.SuppressLint;
- import android.app.Application;
- import android.os.StrictMode;
- import android.util.Log;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class db_class extends Application{
- @SuppressLint("NewApi")
- static Connection ConnectionDB() {
- String url="jdbc:jtds:sqlserver://WIN-H2IOJKV9R76:1433:/Test;";
- String username="khiki";
- String password="12345";
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- java.sql.Connection connection = null;
- try{
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- connection = DriverManager.getConnection(url,username,password);
- }
- catch (SQLException se){
- Log.e("error from SQL",se.getMessage());
- }
- catch(ClassNotFoundException e){
- Log.e("Error from Class",e.getMessage());
- }
- catch (Exception ex){
- Log.e("Error from Exception",ex.getMessage());
- }
- return connection;
- }
- }
Add Comment
Please, Sign In to add comment