Am realizat o conexiune cu baza de date dar vreau daca e posibil sa pot apela conexiunea aia in alte clase ceva de genu new Database(); si asta sa imi aduca tot codul scris in Database pentru a nu scrie de fiecare data asta e codul meu pentru conexiunea cu baza de date import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Database { public static void main(String[] args) { try { // Note : // • SQL Server's port no can be found by using TCPView s/w // OR // • You can also set a fixed port for the server in Sql server TCP/IP // properties // • Sql Server's TCP/IP should be enabled first for this // • A 'SQL' user should be created and GRANTED access to the Database // • Rest is just as normal JDBC Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); System.out.println("# - Driver Loaded"); String server = " "; int port = 1433; String user = ""; // Sql server username String password = "; String database = ""; String jdbcUrl = "jdbc:sqlserver://"+server+":"+port+";user="+user+";password="+password+";databaseName="+database+""; Connection con = DriverManager.getConnection(jdbcUrl); System.out.println("# - Connection Obtained"); Statement stmt = con.createStatement(); System.out.println("# - Statement Created"); ResultSet rs = stmt.executeQuery("SELECT * FROM PERSON;"); System.out.println("# - Query Executed"); if(rs.next()) { System.out.println("Product Count : "+rs.getString(1)); } rs.close(); stmt.close(); con.close(); System.out.println("# - Resources released"); } catch (Exception ex) { System.out.println("Error : "+ex); } } } si asta e clasa mea de Log in import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; public class GUILOGIN extends JFrame { //componente JTextField user; JPasswordField pass; JButton login; JLabel username; JLabel password; //final componente public GUILOGIN() { super("Log in Window"); setSize(300,200); setLayout(null); Componente(); populare(); add(user); add(pass); add(login); add(username); add(password); setResizable(false); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void Componente() { user=new JTextField(15); user.setBounds(70, 30, 150, 20); pass=new JPasswordField(15); pass.setBounds(70, 65, 150, 20); login=new JButton("Log in"); login.setBounds(110,100,80,20); login.addActionListener(actiune); username=new JLabel("Username"); username.setBounds(1,30,70,20); password=new JLabel("Password"); password.setBounds(1, 65, 70, 20); } public void populare() { Vector<Employe> lista = new Vector<Employe>(); Employe dragos=new User(1,"Dragos","12345","Razvan","razvan","normal",0f,0f, 0f, "Comentarii","bonusuri","Penatyss"); Employe george=new Admin(2,"George","344556","George","12345","avansat","Administrator"); lista.add(dragos); lista.add(george); } Actiune actiune=new Actiune(); public class Actiune implements ActionListener { @Override public void actionPerformed(ActionEvent argument) { populare(); Vector<Employe> lista = new Vector<Employe>(); Employe dragos=new User(1,"Dragos","12345","Razvan","razvan","normal",0f,0f, 0f, "Comentarii","bonusuri","Penatyss"); Employe george=new Admin(2,"George","344556","George","12345","avansat","Administrator"); lista.add(dragos); lista.add(george); String pname=user.getText(); String ppass=new String(pass.getPassword()); if(argument.getSource()==login) { for(Employe employes: lista){ if(employes.autentificare(pname, ppass)) { if(employes.permisiuni()==false) { System.out.println("Userul este normal"); dispose(); break; } else if(employes.permisiuni()==true) { System.out.println("Userul este admin"); dispose(); break; } } else { System.out.println("Eroare"); } } } } } }//clasa Final eu vreau sa extrang useri din baza de date si in functie de tip sa apara ceva ..si apoi sa apelez intr-o clasa numita main si sa ruleze