import java.sql.*; /*************************************************************************** * Open a connection to a local MySql instance that contains the * Company database and read the Employee table into the list passsed as * a parameter. * @param emps -- List of employees for the TableView. * * You will almost certainly have to modify this for your purposes, but it * does show how to connect. Use this as you see fit, no attributon, no * penalty. ***************************************************************************/ private void build(ObservableList emps) { Connection cnSQL; String strSql; Statement stmtSQL; String strdata; try { //???Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //???cnSQL = DriverManager.getConnection(strConnect); Class.forName("com.mysql.jdbc.Driver"); cnSQL=DriverManager.getConnection("jdbc:mysql://localhost:3306/company?characterEncoding=utf8","root","SQL1"); stmtSQL = cnSQL.createStatement(); ResultSet rs = stmtSQL.executeQuery("SELECT * FROM Employee"); while (rs.next()) { strdata = rs.getString("fname") + " " + rs.getString("lname"); System.out.println(strdata); Employee emp = new Employee(); emp.setEmployeeID(rs.getString("ssn")); emp.setFname(rs.getString("fname")); emp.setLname(rs.getString("lname")); emp.setAddress(rs.getString("address")); emp.setSalary(rs.getDouble("salary")); emps.add(emp); } cnSQL.close(); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); } }