· 7 years ago · Nov 30, 2018, 01:06 PM
1package it.GestioneAziendaleWeb.controller;
2import java.sql.*;
3public class Database {
4
5 public static void main(String[] args) {
6 Connection conn = null;
7 Persone persona = new Persone(null, null, null);
8 String nome = persona.getNome();
9 String cognome = persona.getCognome();
10 String stipendio = persona.getStipendio();
11
12 try {
13 conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", null);
14 Statement stmt = null;
15 String CreaTabella = "CREATE TABLE IF NOT EXISTS DIPENDENTI(Nome varchar(25), Cognome varchar(25), Stipendio varchar(10))";
16 stmt = conn.createStatement();
17 stmt.execute(CreaTabella);
18 stmt = conn.createStatement();
19 PreparedStatement pst = (PreparedStatement) conn.prepareStatement("INSERT INTO DIPENDENTI(nome,cognome,stipendio) VALUES(?,?,?)");
20 pst.setString(1, nome);
21 pst.setString(2, cognome);
22 pst.setString(3, stipendio);
23
24
25
26
27
28 } catch (SQLException e) {
29
30 e.printStackTrace();
31 }
32 }
33}