Añadida la clase conexion y la apertura del lector de codigos.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.example.saipp.data
|
||||
|
||||
import android.util.Log
|
||||
import java.sql.Connection
|
||||
import java.sql.DriverManager
|
||||
import java.sql.SQLException
|
||||
import java.util.Properties
|
||||
|
||||
object MariaDbConnection {
|
||||
private const val TAG = "MariaDbConnection"
|
||||
|
||||
// TODO: Replace with your actual database details
|
||||
private const val HOST = "YOUR_HOST_IP"
|
||||
private const val PORT = "3306"
|
||||
private const val DATABASE = "YOUR_DATABASE_NAME"
|
||||
private const val USER = "YOUR_USER"
|
||||
private const val PASSWORD = "YOUR_PASSWORD"
|
||||
|
||||
private const val URL = "jdbc:mariadb://$HOST:$PORT/$DATABASE"
|
||||
|
||||
fun getConnection(): Connection? {
|
||||
return try {
|
||||
// Load the driver explicitly if needed
|
||||
Class.forName("org.mariadb.jdbc.Driver")
|
||||
|
||||
val props = Properties()
|
||||
props.setProperty("user", USER)
|
||||
props.setProperty("password", PASSWORD)
|
||||
props.setProperty("connectTimeout", "5000") // 5 seconds timeout
|
||||
|
||||
DriverManager.getConnection(URL, props)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error connecting to MariaDB: ${e.message}", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user