<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-mysql_2.12</artifactId>
<version>21.7.0</version>
</dependency>
import com.twitter.finagle.mysql.*;
import com.twitter.finagle.mysql.transport.MysqlTransport;
import com.twitter.finagle.mysql.transport.SimpleCommandHandler;
public class MySQLClient {
public static void main(String[] args) {
Mysql.Transactions transactions = Mysql.client().newRichClient("localhost:3306");
MysqlTransport transport = transactions.transport();
Mysql.Client client = transactions.client();
client.query("SELECT * FROM users")
.onSuccess(result -> {
for (Row row : result.rows()) {
System.out.println(row.getString("username"));
}
}).onFailure(e -> {
e.printStackTrace();
}).ensure(() -> {
transport.close();
});
}
}
yaml
com.twitter.finagle {
mysql.client {
host = "localhost"
port = 3306
username = "your-username"
password = "your-password"
database = "your-database"
}
}