K
K
KaizerSX2019-12-04 11:35:09
Java
KaizerSX, 2019-12-04 11:35:09

How to maintain a connection to the current H2 table in the database?

Good afternoon !
I'm just getting familiar with H2 DB and here's a question.
Here is the connection being created:

Connection connection=null;

          try{

              Class.forName("org.h2.Driver");
              
              connection= DriverManager.getConnection("jdbc:h2:~/test");
              System.out.println("Connection ok");
              Statement stat = connection.createStatement();
              
            stat.execute("create table test(id var(255) primary key, name varchar(255), age int)")

I do not understand how, for example, when adding a record to a table, do not create a new table each time, but work with the current one (which is already in the database)? After all, for each operation, such as inserting, extracting information or deleting, I will need to maintain a connection with the current table.
In normal DBMS, the table and the database are created separately on a separate server and do not depend on my java code, but with this database I can’t understand how and what.
Can you describe an example code for me, let's say a method for inserting and a method for extracting from the same table without creating a new table each time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
koperagen, 2019-12-04
@koperagen

The key point in the table creation line.
So it will not be recreated:

stat.execute("create table if not exists test(id var(255) primary key, name varchar(255), age int)")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question