Hi everyone,
I had designed an application with Java as front end and mysql as back end. The client application uses both local database as well as Remote mysql server's database for login and other retrievals.
I don't know how to generalize the database connectivity code?, I need to access a remote database for more than couple of times,for each time I am creating a new connection(copy paste the same code) and just changing the query, my program size increases and retrievals take more time(>1min).
Connection connect1 = null;
Statement statement1 = null;
ResultSet rs1 = null;
float available_qty;
public purchase() {
initComponents();
try{
int i;
String username = "root";
String password = "root";
String url = "jdbc:mysql://172.16.36.55:3306/shop";
Class.forName("com.mysql.jdbc.Driver");
connect1 = DriverManager.getConnection(url, username, password);
statement1 = connect1.createStatement();
rs1 = statement1.executeQuery("select * from product");
int flag=0;
while(rs1.next())
{
int size=jComboBox1.getItemCount();
int tbl_p_id=rs1.getInt("p_id");
String tbl_pname=rs1.getString("pname");
int tbl_p_no_qty=rs1.getInt("p_no_qty");
float tbl_p_cost=rs1.getFloat("p_cost");
for(i=0;i<size;i++)
{
String temp=jComboBox1.getItemAt(i).toString();
if(temp.equals(tbl_pname))
{
flag=1;
break;
}
}
if(flag==0)
jComboBox1.addItem(tbl_pname);
}
}catch(Exception e)
{
System.out.println("Database connectivity Error ");
}
For simple Login the client takes more than 30 seconds,how to speed up the login process?
Any idea?