8b27e7ea33589528aa2fe032a461d76b22909ee2
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
8 import java
.util
.ArrayList
;
9 import java
.util
.prefs
.Preferences
;
11 import java
.util
.logging
.Level
;
12 import java
.util
.logging
.Logger
;
18 public class Utility
{
20 static void setConnectionURL(String text
) {
22 Preferences
.userRoot().put("ConnectionURL", text
);
25 static ArrayList
<Object
> getClientDetails(int r
) {
26 ArrayList
<Object
> res
= new ArrayList
<>();
28 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:"+connectionURL
);
29 PreparedStatement st
= conn
.prepareStatement("SELECT * FROM clients WHERE id=?;");
31 ResultSet rs
= st
.executeQuery();
33 res
.add (rs
.getString("ClientName"));
34 res
.add(rs
.getString("ClientAddress"));
35 res
.add (rs
.getString("ContactPerson"));
36 res
.add (rs
.getString("MailID"));
37 res
.add (rs
.getString("ContactNumber"));
42 } catch (SQLException ex
) {
43 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
49 static boolean addClient(String client_name
, String client_address
,
50 String contact_person
, String email_id
, String phone_number
) {
51 if ("".equals(client_name
))
54 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:" + connectionURL
);
55 PreparedStatement st
= conn
.prepareStatement("INSERT INTO clients (ClientName,"
56 + "ClientAddress, ContactPerson, MailID, ContactNumber) VALUES (?, ?, ?, ?, ?);");
57 st
.setString(1, client_name
);
58 st
.setString(2, client_address
);
59 st
.setString(3, contact_person
);
60 st
.setString (4, email_id
);
61 st
.setString (5, phone_number
);
66 } catch (SQLException ex
) {
67 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
74 static boolean deleteClient(int r
) {
76 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:" + connectionURL
);
77 PreparedStatement st
= conn
.prepareStatement("DELETE FROM clients WHERE id=?;");
78 PreparedStatement st2
= conn
.prepareStatement("DELETE FROM legalnotices WHERE ClientId=?;");
85 } catch (SQLException ex
) {
86 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
92 static boolean updateClient(int r
, String client_name
, String client_address
,
93 String contact_person
, String mail_id
, String phone_number
) {
94 if ("".equals(client_name
))
97 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:" + connectionURL
);
98 PreparedStatement st
= conn
.prepareStatement("UPDATE clients SET "
99 + "ClientName=?, ClientAddress=?,"
100 + "ContactPerson=?, MailID=?, ContactNumber=? WHERE id=?;");
101 st
.setString(1, client_name
);
102 st
.setString(2, client_address
);
103 st
.setString(3, contact_person
);
104 st
.setString(4, mail_id
);
105 st
.setString(5, phone_number
);
110 } catch (SQLException ex
) {
111 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
118 static boolean addLegalNotice(String reference_number
,
119 String description
, java
.util
.Date entrustment_date
, DBItem client
) {
120 if ("".equals(reference_number
) || "".equals(description
) ||
121 entrustment_date
== null)
124 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:" + connectionURL
);
125 PreparedStatement st
= conn
.prepareStatement("INSERT INTO legalnotices"
126 + " (ReferenceNumber, Description, EntrustmentDate, ClientId) "
127 + "VALUES (?, ?, ?, ?);");
128 st
.setString(1, reference_number
);
129 st
.setString(2, description
);
130 st
.setLong(3, entrustment_date
.getTime()/1000);
131 st
.setInt (4, client
.getKey());
136 } catch (SQLException ex
) {
137 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
145 public static String connectionURL
;
151 public static ArrayList
<Object
> getClientsNameAndId () {
152 ArrayList
<Object
> data
= new ArrayList
<>();
154 Connection conn
= DriverManager
.getConnection("jdbc:sqlite:" + connectionURL
);
155 Statement st
= conn
.createStatement();
156 ResultSet rs
= st
.executeQuery("SELECT id, ClientName from clients;");
158 data
.add(rs
.getInt("id"));
159 data
.add(rs
.getString("ClientName"));
163 } catch (SQLException ex
) {
164 Logger
.getLogger(Utility
.class.getName()).log(Level
.SEVERE
, null, ex
);
170 public static void getConnectionURL () {
171 connectionURL
= Preferences
.userRoot().get("ConnectionURL", "legaldb");