Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Program Speed database connection
    primarykey
    data
    text
    <p>I've finished writing my first java program that accesses a database and allows me to remote onto machines.</p> <p>This works ok when I run it from my own machine (which also hosts the database it connects to). However, if I use it on another machine and connect to the database the program hangs considerably while it does the database task.</p> <p>I expected it to be a small wait, however sometimes it can take afew miniutes before it finish's the task at hand.</p> <p>Heres one of the tasks that it hangs on.</p> <pre><code> public void ChangeSite() throws Exception{ ConnectionPoolS demo = new ConnectionPoolS(); DataSource dataSource = demo.setUp(); Connection conn = null; PreparedStatement stmt = null; String Site = (String)Sites.getSelectedItem(); jProgressBar.setIndeterminate(true); jProgressBar.setStringPainted(true); jProgressBar.setString("Searching..."); int sRecordNo; sRecordNo = 0; String IpAddress = null, IpRange = null, Atvisionpw = null, Port = null, Practice = null, Surgery = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement("SELECT * FROM Customer WHERE Practice = '"+Site+"' and BRANCH = 'N'"); ResultSet rs = stmt.executeQuery( ); while (rs.next()) { sRecordNo = sRecordNo + 1; Surgery = rs.getString("SURGERY"); Practice = rs.getString("PRACTICE"); IpAddress = rs.getString("IPADDRESS"); Port = rs.getString("PORT"); Atvisionpw = rs.getString("ATVISIONPW"); IpRange = rs.getString("IPRANGE"); } if (sRecordNo == 1){ SiteIp.setText(IpAddress); Password.setText(Atvisionpw); PcIp.setText(IpRange); } else if (sRecordNo &gt; 1){ Multisite(); } jProgressBar.setIndeterminate(false); jProgressBar.setString(""); stmt.close(); conn.close(); } </code></pre> <p>This is all on a derby database.</p> <p>What I am doing wrong? I am missing something? Is there a way I can run some kind of performance check on this to find out what exactly is causing it to hang while running the database task, as this is all internal on an internal network I wouldn't expect to be waiting as much as I am!</p> <p>Edit: With some help from Stefan (Thanks a bunch) ive found that that using the break points it seems hang after running the line</p> <pre><code>conn = dataSource.getConnection(); </code></pre> <p>the next line after that is now </p> <pre><code>stmt = conn.prepareStatement("SELECT * FROM Customer WHERE Practice = '"+Site+"' and BRANCH = 'N'"); </code></pre> <p>but it only hangs after running the Connection line so would this mean the connection to the physical database is causing the hang?</p> <p>Edit2: I have now setting a Connection Pool, however its still hanging when connecting, im at a bit of a loss now!, would a different engine provide better results?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload