4
I have a swing java application that is connected to a remote Mysql database, that is, on an online server.
When running the program it works normal, except for the slow response of the bank. For example, I open the user registration window and it takes about 20 seconds to open. this problem did not happen when I was with the local bank.
Here the code that connects to the bank:
public java.sql.Connection conectaBanco() {
Connection conn = null; //pro compilador ficar feliz
try {
// Carrega o driver JDBC
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
System.out.println("ok");
// Configuração da conexão com um Conexao1 de dados//
//troque por seu ip, senha, user, etc
String serverName = "aqui vai o server onde o banco está";
//caminho do servidor do BD - para acesso local coloque : localhost
String mydatabase ="nome_do_banco"; //nome do seu banco de dados
String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
System.out.println("ok");
String user = "nome_do_usuario"; //nome de um usuário de seu BD
String key = "senha"; //sua senha de acesso
conn = DriverManager.getConnection(url, user, key);
//Testa sua conexão//
System.out.println("Conectado!");
return conn;
} catch (ClassNotFoundException e) { //Driver não encontrado
System.out.println("O driver expecificado nao foi encontrado.");
} catch (SQLException e) {
//Não conseguindo se conectar ao Conexao1
System.out.println("Nao foi possivel conectar ao Banco de Dados.");
}
return conn;
}
One of the consultations:
SELECT * FROM Table Name_table
Welcome to Stack Overflow Filipe! I suggest you include the snippet of the code that makes the request to the database - it will give a better idea to the staff than is occurring! :)
– Daniel
edited the post, please look at it.
– Filipe Sampaio
It usually takes a little longer even, locally it is much faster, which server is your bank hosted? You could post this query that takes 20 seconds?
– Rafael Ferreira
+1 pro @Rafaelferreira - Removing the server question, which is usually considered confidential information ;) - Include the 20 seconds query, as that’s probably where the problem is.
– Daniel
Look, the server I’m using is hostgator. While the query, it’s all of them! Anything I do takes 15 to 30 seconds! I put a simple SELECT query up there.
– Filipe Sampaio
you are making queries via Linq or lambda?
– Rafael Ferreira