package com.example.zonic

import android.os.StrictMode
import android.os.StrictMode.ThreadPolicy
import android.util.Log
import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException


object ConnectionHelper {
    val ip = "ngknn.ru"
    val port = "1433"
    val database = "Zonic"
    val userName = "43П"
    val userPassword = "444444"
    val driver = "net.sourceforge.jtds.jdbc.Driver"
    fun Connection(): Connection? {
        val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
        StrictMode.setThreadPolicy(policy)
        var connection: Connection? = null
        var connectionURL: String? = null
        try {
            Class.forName(driver)
            connectionURL = "jdbc:jtds:sqlserver://$ip:$port/$database"
            connection = DriverManager.getConnection(connectionURL, userName, userPassword)
        } catch (se: SQLException) {
            se.message?.let { Log.e("ERROR", it) }
        } catch (e: ClassNotFoundException) {
            e.message?.let { Log.e("ERROR", it) }
        } catch (e: Exception) {
            e.message?.let { Log.e("ERROR", it) }
        }
        return connection
    }
}