Help, I am not able to make the login work, I don’t even enter the if to show one of the 2 messages to log in.
import java.sql.*
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.btnIniciar)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val buttonLogIn: Button = findViewById(R.id.boton)
buttonLogIn.setOnClickListener {
var usr: EditText = findViewById(R.id.usuario)
var verUsr: String = usr.text.toString()
var pass: EditText = findViewById(R.id.password)
var verPass: String = pass.text.toString()
val url = "jdbc:mysql://basedatos.c1wuymgaofdd.us-west-1.rds.amazonaws.com/bd_sistema_ventas"
val user = "admin"
val password = "storemanager"
try {
val connection: Connection = DriverManager.getConnection(url, user, password)
val statement = connection.prepareStatement("SELECT * FROM tb_usuario where usuario = ? AND password = ?")
statement.setString(1, verUsr)
statement.setString(2, verPass)
val resultSet = statement.executeQuery()
if (resultSet.next()) {
// Login successful
val entrarE = Intent(this, MenuPrincipal::class.java)
startActivity(entrarE)
println("User logged in successfully!")
} else {
// Login failed
println("Invalid username or password.")
}
} catch (e: SQLException) {
null
}
}
}
}
already has
and implementation (“mysql:mysql-connector-java:8.0.28”)
HELLLPPPP
I would like you to explain to me how to make a connection correctly because I have seen several methods that did not work, as well as knowing where I went wrong.
New contributor
Lord Doc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.