Столбцы есть, записей в БД нет.
Ошибка при компиляции:
org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: m.UsersId)
at org.sqlite.core.DB.newSQLException(DB.java:941)
at org.sqlite.core.DB.newSQLException(DB.java:953)
at org.sqlite.core.DB.throwex(DB.java:918)
......
......
org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: c.ContractId)
at org.sqlite.core.DB.newSQLException(DB.java:941)
at org.sqlite.core.DB.newSQLException(DB.java:953)
at org.sqlite.core.DB.throwex(DB.java:918)
...... ......
Код:
package gui;
import javax.swing.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class contactQuery {
public boolean insertContact(Contact cont)
{
boolean ContactIsCreated = true;
try (Connection connection = DriverManager.getConnection("jdbc:sqlite:mase.db", "root", "root")){
try(PreparedStatement ps = connection.prepareStatement("INSERT INTO Users ( First_Name, Last_Name) VALUES (?, ?)"))
{
ps.setString(1, cont.getFirst_name());
ps.setString(2, cont.getLast_name());
ps.executeUpdate();
if(ps.executeUpdate()!=0){
JOptionPane.showMessageDialog(null, "New Contact Added1");
ContactIsCreated = true;
}
else{
JOptionPane.showMessageDialog(null,"something wrong");
ContactIsCreated = false;
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(PreparedStatement ps = connection.prepareStatement("INSERT INTO PhoneNumbers (NumberPrefix,Number) VALUES (?,?)")) {
ps.setString(1, cont.getNumberPrefix());
ps.setString(2, cont.getNumber());
ps.executeUpdate();
if (ps.executeUpdate() != 0) {
JOptionPane.showMessageDialog(null, "New Contact Added2");
ContactIsCreated = true;
} else {
JOptionPane.showMessageDialog(null, "something wrong");
ContactIsCreated = false;
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(PreparedStatement ps = connection.prepareStatement("INSERT INTO SRates (Rates) VALUES (?)"))
{
ps.setString(1, cont.getRates());
ps.executeUpdate();
if (ps.executeUpdate() != 0) {
JOptionPane.showMessageDialog(null, "New Contact Added3");
ContactIsCreated = true;
} else {
JOptionPane.showMessageDialog(null, "something wrong");
ContactIsCreated = false;
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(PreparedStatement ps = connection.prepareStatement("INSERT INTO Pay ( Amount, PaymentDate, PaymentPlace ) VALUES (?,?,?) ")){
ps.setString(1, cont.getAmount());
ps.setString(2, cont.getPaymentDate());
ps.setString(3, cont.getPaymentPlace());
ps.executeUpdate();
if (ps.executeUpdate() != 0) {
JOptionPane.showMessageDialog(null, "New Contact Added5");
ContactIsCreated = true;
} else {
JOptionPane.showMessageDialog(null, "something wrong");
ContactIsCreated = false;
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(PreparedStatement ps = connection.prepareStatement("INSERT INTO Cont ( StartDate,Balance,IsActive ) VALUES (?,?,?) ")){
ps.setString(1, cont.getStartDate());
ps.setString(2, cont.getBalance());
ps.setString(3, cont.getIsActive());
ps.executeUpdate();
if (ps.executeUpdate() != 0) {
JOptionPane.showMessageDialog(null, "New Contact Added6");
ContactIsCreated = true;
} else {
JOptionPane.showMessageDialog(null, "something wrong");
ContactIsCreated = false;
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(Statement statement = connection.createStatement()){
String sql = "INSERT INTO Contracts (Id, UsersId, PhoneNumbersId, RatesId, StartDate, Balance, IsActive ) SELECT y.Id, m.UsersId, p.PhoneNumbersId,r.RatesId, StartDate, Balance, IsActive FROM Cont y LEFT JOIN Users m ON m.Id=y.Id LEFT JOIN PhoneNumbers p ON p.Id=y.Id LEFT JOIN SRates r ON r.Id=y.Id";
Boolean isRetrieved = statement.execute(sql);
System.out.println("Is data retrieved: " + isRetrieved);
try {
statement.close();
connection.close();
}
finally
{
if (statement != null)
{
statement.close();
}
if (connection != null)
{
connection.close();
}
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
try(Statement statement = connection.createStatement()){
String sql = " INSERT INTO Payments (Id, ContractId, Amount, PaymentDate, PaymentPlace) SELECT x.Id, c.ContractId , Amount, PaymentDate, PaymentPlace FROM Pay x INNER JOIN Contracts c ON c.Id=x.Id";
Boolean isRetrieved = statement.execute(sql);
System.out.println("Is data retrieved: " + isRetrieved);
try {
statement.close();
connection.close();
}
finally
{
if (statement != null)
{
statement.close();
}
if (connection != null)
{
connection.close();
}
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
}
catch(SQLException ex)
{
Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE,null,ex);
}
return ContactIsCreated;
}
}