Я хочу сохранить значение имени в базе данных, тип данных для столбца имени - Короткий текст, но я всегда получаю сообщение об ошибке как недопустимое значение символа для приведения.
Я уже пробовал использовать обычный класс Statementвместо PreparedStatement, но я получил ту же проблему.Вот код для того же
public void actionPerformed(ActionEvent e) {
System.out.println(cid);
id = Integer.parseInt(pid.getText());
name = pname.getText();
quant = Integer.parseInt(quantity.getText());
pr = Integer.parseInt(price.getText());
tx = Integer.parseInt(tax.getText());
System.out.println(name);
String query = "Insert into Product values ( ? , ? , ? , ? , ? , ?)";
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://src\\ERP_System\\Database\\ERPdb.accdb");
PreparedStatement stmt = con.prepareStatement(query);
stmt.setInt(1,id);
stmt.setInt(2,cid);
System.out.println("Hello");
stmt.setString(3, name); // error is triggerred by this statement
System.out.println("Hello2");
stmt.setInt(3,pr);
stmt.setInt(4,tx);
stmt.setInt(5,quant);
ResultSet rs;
stmt.execute();
System.out.println("Hello3");
} catch (ClassNotFoundException | SQLException ex) {
ex.printStackTrace();
}
}
I keep getting the error as
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 data exception: invalid character value for cast
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.setString(UcanaccessPreparedStatement.java:742)
at ERP_System.AddProduct.actionPerformed(AddProduct.java:104)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
.
.
.
.
.
The dots are just to represent more and more lines of errors.
Here are the details for the product table
[1]: https://i.stack.imgur.com/fFN5m.png