当我与Java Dao建筑师合作时,我有一个外键时遇到了问题

发布于 2025-01-23 15:07:18 字数 1599 浏览 4 评论 0原文

我有一个有关Java Ana Dao设计的银行帐户管理的Java项目。我从事班级女巫的工作取决于客户班和帐户(法语中的compte)课程。


操作变量类是这样的:

private String DateDebut ;
private String DateFin ;
private String NumeroOperation ;
private String TypeOperation ;
private Compte Compte ;
private Client Client ;
public Operation(String numeroOperation, String typeOperation, String dateDebut, String dateFin, Compte compte,Client client) {
    DateDebut = dateDebut;
    DateFin = dateFin;
    NumeroOperation = numeroOperation;
    TypeOperation = typeOperation;
    Compte =compte ;
    Client = client ;
}

我在aperipdao类中写下以查找其ID的操作:

public Operation findById (String code) {
    Connection  cnx = Sconnection.getInstance() ;
    Operation op=null;
    try {       
    PreparedStatement req = cnx.prepareStatement("select * from operation where numerOperation = ? ");
    req.setString(1, code);
    
    ResultSet res=  req.executeQuery();
        while (res.next())
        {
            op = new Operation(code, res.getString(2),res.getString(3),res.getString(4),res.getString(5),res.getString(6)) ;
            System.out.println(res.getString(2) +" " +res.getString(3)+" " +res.getString(4));
        }
    req.close();
    }catch (SQLException e)
    {System.out.println("Erreur de chargement de client.. verifier !!"+ e.getMessage());}
    
    return op;
    }

但是我在这一行中遇到了问题:

op = new Operation(code,res.getString(2),res.getString(3),res.getString(4),res.getString(5),res.getString(6)) ;

但是在数据库操作表中,就像这样

​我应该如何保存或更新或找到外国钥匙的变量。

I had a java project about bank account managing with java ana DAO Design. I work in operation class witch is depend to client class and account(compte in french ) class.


operation variable class is like that:

private String DateDebut ;
private String DateFin ;
private String NumeroOperation ;
private String TypeOperation ;
private Compte Compte ;
private Client Client ;
public Operation(String numeroOperation, String typeOperation, String dateDebut, String dateFin, Compte compte,Client client) {
    DateDebut = dateDebut;
    DateFin = dateFin;
    NumeroOperation = numeroOperation;
    TypeOperation = typeOperation;
    Compte =compte ;
    Client = client ;
}

and I write in OperationDAO Class that to find operation By their ID:

public Operation findById (String code) {
    Connection  cnx = Sconnection.getInstance() ;
    Operation op=null;
    try {       
    PreparedStatement req = cnx.prepareStatement("select * from operation where numerOperation = ? ");
    req.setString(1, code);
    
    ResultSet res=  req.executeQuery();
        while (res.next())
        {
            op = new Operation(code, res.getString(2),res.getString(3),res.getString(4),res.getString(5),res.getString(6)) ;
            System.out.println(res.getString(2) +" " +res.getString(3)+" " +res.getString(4));
        }
    req.close();
    }catch (SQLException e)
    {System.out.println("Erreur de chargement de client.. verifier !!"+ e.getMessage());}
    
    return op;
    }

but I had a problem in this line :

op = new Operation(code,res.getString(2),res.getString(3),res.getString(4),res.getString(5),res.getString(6)) ;

but in dataBase operation Table is like this

PHP MyAdmin

but I don't know how I should save or update or find variable of foreign keys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-01-30 15:07:18

我从您的解释中了解的是,您想将Compte和客户端保存在操作类中。

问题出现在您初始化操作类的位置。

由于Numerocompt和Numeroclient都是外键,因此您需要进行2个DB调用,以从Numerocompt和NumeroClient中获取COMPT的详细信息,

而更新您必须执行相同的操作。进行2个更新的调用,以将详细信息保存在其他表中。

移动使用Hibernate/JPA将使您的生活变得更加轻松。

What I understood from your explanation is that you want to save Compte and Client in Operation class.

Problem arises where you are initializing Operation class.

Since both NumeroCompt and NumeroClient is foreign key you need to make 2 more DB calls to get details of Compt from NumeroCompt and Client from NumeroClient

While update you have to do the same. Make 2 more update calls to save details in other table.

Moving to use Hibernate/JPA will make your life a lot easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文