java - Desktop application and DB connection -


lets have desktop application simple login - here, in part have create connection, prepared statement compares username , password. use cardlayout- , example, on card (jpanel) have jtable , jbutton retrieves values sql table jtable.... on third jpanel have example fields name , password - using new employee - give name , password - after button click data inserted db

now question: how work in real application? shall make 1 static method (e.g. getdbconnection()) create connection (first login - after login close connection, create connection when want select db close , again if want insert something?) `

or how in smarter/ proper way?

you can write properties file specific application , write class load it.

mydatabaseproperties.properties

database.jdbc.url = jdbc:mysql://localhost:3306/database database.jdbc.driver = "com.mysql.jdbc.driver" database.jdbc.username = "username" database.jdbc.password = "password" 

properties.java:

public class properties {     private static final string properties_file = "mydatabaseproperties.properties";     private static final properties properties = new properties();      static {         try {             properties.load(new fileinputstream("mydatabaseproperties.properties"));         } catch (ioexception e) {             // throw exception here.         }     } } 

you find excellent material on subject here.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -