Does Connection Pooling makes Java Swing Application works faster for remote MySQL database

懵懂的女人 提交于 2019-12-25 18:49:12

问题


I have Created an Java Swing Application with MySQL as the database, Now i am hosting my MySQL database online and Swing Application will be stored locally, Now in order to experiment i have hosted my database i.e MySQL database on https://www.freemysqlhosting.net/ account as it allows free hosting for certain period, Also Connection is successfull and works but the application works too slow suppose if i have to search any entry from the swing aplication from the oline hosted database it works too slow,it is happening like i have to press any key or button and has to wait for the processing of the transaction. Does connection pooling technique will solve the performance issues, If yes which is best one and if not what can i do to solve this. Please Help

Below is the code which i have written to make database transactions and i am doing this everytime i make a database access

public  ArrayList<ChargeSheet> readByAllCompanyInfo(String cityname)
{
ArrayList<ChargeSheet> list = new ArrayList<ChargeSheet>();
con=db.getConnection();
try{
    pst = con.prepareStatement("select * from tblcompanyinformation where companyname = ?");
    pst.setString(1,cityname);
    rs = pst.executeQuery();
    while(rs.next()){
        ChargeSheet clientInformation=new ChargeSheet();
        clientInformation.setRecieptno(rs.getInt(2));
        clientInformation.setPresentdate(rs.getString(3));
        clientInformation.setCompanyname(rs.getString(4));
        clientInformation.setPhone(rs.getString(5));
        list.add(clientInformation);   
    }
}
catch(SQLException ex){
    setLastError(ex.getMessage());
}
finally{
    db.closeConnection();
}
return list;   
}

回答1:


With that code, it is likely that using a connection pool will improve performance. Especially if you are using SSL-enabled connections.

(Of course, this assumes that you use the same pool for connecting.)

If yes which is best one ....

Recommendations are Off-Topic for StackOverflow, but I'm sure you could find a website that lists and compares some popular alternatives.



来源:https://stackoverflow.com/questions/40358852/does-connection-pooling-makes-java-swing-application-works-faster-for-remote-mys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!