-2

So i have the homework to make a WEB application that includes two different tables from MySQL workbench. My question is, how do i do that? Also, i need to make both of tables interactable. With the connector and all that?

I've tried to google basicly everything and there is no explenation so i'm kinda stuck at this point.

Wolf98
  • 1
  • This is not a help forum, and your question does not show any research effort at all. Your question is liable to be closed since ["Questions asking for homework help **must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it**"](https://stackoverflow.com/help/on-topic). Your question is also far too broad in scope. Limit your question to a specific problem. – skomisa Oct 30 '19 at 14:38

2 Answers2

0

Actually to work with a database schema, you need to make a connection with it. After that, you can query any database entities such as tables, views, stored procedures, ... which are associated to that schema. Without using any connection pool (which is very common in Java projects) you can use some code like this:

Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/javabase";
String username = "java";
String password = "password";

System.out.println("Connecting database...");

try (Connection connection = DriverManager.getConnection(url, username, password)) {
    System.out.println("Database connected!");
    //execute any query
} catch (SQLException e) {
    throw new IllegalStateException("Cannot connect the database!", e);
}

However, I suggest using a connection pool which is more practical. You can also refer to this thread which provides you some detail information. Connect Java to a MySQL database

0

If I understood your problem right... This tutorial could help you

Liam Park
  • 414
  • 1
  • 9
  • 26