Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Connection connection;
- private Statement statement;
- private ResultSet result;
- public DBConnect(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://localhost:1234/practicedb"); //code stucks here and after some minutes it is throwing an exception
- System.out.println("Connected");//this is never executed.
- statement = connection.createStatement();
- } catch (Exception ex) {
- System.out.print("Error in Constractor: "+ex);
- }
- }
- public void getData() {
- try {
- String query = "select * from cars";
- result = statement.executeQuery(query);
- while (result.next()) {
- String name = result.getString("carName");
- String id = result.getString("carID");
- String modelNum = result.getString("modelNumber");
- System.out.println("Car name: " + name + ", " + "Car ID: " + id + ", " + "Car model number: " + modelNum);
- }
- } catch (Exception ex) {
- System.out.println(ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement