-1

I'm currently trying to connect my first database with Java. I've followed a tutorial but I still have 3 errors that I'm unable to deal with. It seems to be common errors but none of the methods that I've seen have worked until now.

I show you first my imports :

import com.sun.jdi.connect.spi.Connection;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;` 

Then I show you the place inn the code where the error seems to occur :

        try {
        Class.forName("org.sqlite.JDBC");
        String url = "jdbc:sqlite:biblio.db";
        String name = "root";
        String pass = "";
        con = (Connection) DriverManager.getConnection(url, name, pass);
        String sql = "insert into Clients (id, nom, prenom, date_naissance, nationalite) values (?,?,?,?,?)";
        pst = con.PreparedStatement(sql);
        pst.setString(2,txtnom.getText());
        pst.setString(3,txtprenom.getText());
        pst.setString(4,txtdatedenaissance.getText());
        pst.setString(5,txtnationalite.getText());
        pst.executeUpdate();
        con.close();
        JOptionPane.showMessageDialog(null,"Enregistrement réussi");
        TableClients();
    }catch (Exception e) {
        e.printStackTrace();
    }
}

And the second block is :

        try{
        Class.forName("org.sqlite.JDBC");
        String url = "jdbc:sqlite:biblio.db";
        String name = "root";
        String pass = "";
        con = (Connection) DriverManager.getConnection(url, name, pass);
        Statement st = con.CreateStatement();
        rs = st.executeQuery(sql);

You can see what are the errors with the screenshot Screenshot of the error

Basically, it can't find the two methods (PreparedStatements and CreateStatements) used and I can't figure out why. Does anyone know how to fix that ?

Thanks for your time and I hope I've respect the due format on Stack.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Names (specifically, in this case, method names) in Java are case sensitive. The methods are called prepareStatement and createStatement, respectively, with lower case first letters.

Mureinik
  • 297,002
  • 52
  • 306
  • 350