Hi i want to be able to connect to an sql database and load the info (customer, which has Customernumber, Name, Street, Suburb) this is what i have done so far am a bit lost because i have already set up my entire program to read from a .dat file. Any help much appreciated
And then to load in my main in my GUICode:import java.sql.*; public class CustomerSql{ Connection conn; Statement stmt; public CustomerDatabase loadCustomers(){ CustomerDatabase customerDB = new CustomerDatabase(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:cdbCustomers"; conn = DriverManager.getConnection(url, null, null); customerDB.add(add()); } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } return customerDB; } public ResultSet add() throws SQLException{ Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM Customer"); while(rs.next()){ } return rs; } }
CustomerDatabase cbd = (new CustomerSql()).loadCustomers();


Reply With Quote


Bookmarks