admin I'm goning to crazy, and this situation is when I think it doesn't work. My behavior is indeed within the scope of the services provided by Serv00. You can see the following code is a situation where I can remotely connect to a local server
test.kt
package com.lynb.test
import org.junit.jupiter.api.Test
import java.sql.Connection
import java.sql.DriverManager
import kotlin.concurrent.thread
//Test class that simulates the occurrence of events in a MySQL database
class mysqlTest {
//Define variables for connecting to MySQL database
//My own MySQL server details
private val connectionUrl1 = "jdbc:mysql://xxx:3306/xxx"
private val username1 = "xxx"
private val password1 = "xxx"
//MySQL server provided by Serv00
private val connectionUrl2 = "jdbc:mysql://mysql'xxx'.serv00.com:3306/m'xxx'_'xxx'"
private val username2 = "m'xxx'_'xxx'"
private val password2 = "xxx"
fun connectInit(url: String, username: String, password: String): Connection {
Class.forName("com.mysql.cj.jdbc.Driver")
val connection = DriverManager.getConnection(url, username, password)
return connection
}
@Test
fun test1() {
thread {
run {
//Test case 1: Connect to my own MySQL server
connectTest1()
createTableTest()
insertDataTest()
selectDataTest()
deleteDataTest()
updateDataTest()
dropTableTest()
}
}.run()
}
@Test
fun test2() {
thread {
run {
//Test case 2: Connect to Serv00 MySQL server
connectTest2()
createTableTest2()
insertDataTest2()
selectDataTest2()
deleteDataTest2()
updateDataTest2()
dropTableTest2()
}
}.run()
}
fun connectTest1() {
val connection = connectInit(connectionUrl1, username1, password1)
connection.close()
}
fun connectTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
connection.close()
}
fun createTableTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.createStatement()
statement.execute("CREATE TABLE IF NOT EXISTS testTable (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50), age INT)")
statement.close()
connection.close()
}
fun createTableTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.createStatement()
statement.execute("CREATE TABLE IF NOT EXISTS testTable (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50), age INT)")
statement.close()
connection.close()
}
fun insertDataTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.prepareStatement("INSERT INTO testTable (name, age) VALUES (?,?)")
statement.setString(1, "John")
statement.setInt(2, 25)
statement.executeUpdate()
statement.setString(1, "Jane")
statement.setInt(2, 30)
statement.executeUpdate()
statement.close()
connection.close()
}
fun insertDataTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.prepareStatement("INSERT INTO testTable (name, age) VALUES (?,?)")
statement.setString(1, "John")
statement.setInt(2, 25)
statement.executeUpdate()
statement.setString(1, "Jane")
statement.setInt(2, 30)
statement.executeUpdate()
statement.close()
connection.close()
}
fun selectDataTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.prepareStatement("SELECT * FROM testTable")
val resultSet = statement.executeQuery()
while (resultSet.next()) {
val id = resultSet.getInt("id")
val name = resultSet.getString("name")
val age = resultSet.getInt("age")
assert(id != null && name != null && age != null)
}
statement.close()
connection.close()
}
fun selectDataTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.prepareStatement("SELECT * FROM testTable")
val resultSet = statement.executeQuery()
while (resultSet.next()) {
val id = resultSet.getInt("id")
val name = resultSet.getString("name")
val age = resultSet.getInt("age")
assert(id != null && name != null && age != null)
}
statement.close()
connection.close()
}
fun deleteDataTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.prepareStatement("DELETE FROM testTable WHERE id = ?")
statement.setInt(1, 1)
statement.executeUpdate()
statement.close()
connection.close()
}
fun deleteDataTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.prepareStatement("DELETE FROM testTable WHERE id = ?")
statement.setInt(1, 1)
statement.executeUpdate()
statement.close()
connection.close()
}
fun updateDataTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.prepareStatement("UPDATE testTable SET name = ?, age = ? WHERE id = ?")
statement.setString(1, "Johnny")
statement.setInt(2, 26)
statement.setInt(3, 1)
statement.executeUpdate()
statement.close()
connection.close()
}
fun updateDataTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.prepareStatement("UPDATE testTable SET name = ?, age = ? WHERE id = ?")
statement.setString(1, "Johnny")
statement.setInt(2, 26)
statement.setInt(3, 1)
statement.executeUpdate()
statement.close()
connection.close()
}
fun dropTableTest() {
val connection = connectInit(connectionUrl1, username1, password1)
val statement = connection.createStatement()
statement.execute("DROP TABLE IF EXISTS testTable")
statement.close()
connection.close()
}
fun dropTableTest2() {
val connection = connectInit(connectionUrl2, username2, password2)
val statement = connection.createStatement()
statement.execute("DROP TABLE IF EXISTS testTable")
statement.close()
connection.close()
}
}
test.kt
Okay, there's another issue. Running it directly is fine, but there's a problem running it on the server. Let me double check first and note that my problem hasn't ended yet. I can only hope that you will continue to pay attention to my issue when you have time