JFrame 및 일련의 텍스트 필드에서 입력 한 데이터를 데이터베이스 테이블에 삽입하려고합니다. 나는 소량의 데이터로 그렇게 할 수 있었지만, 이것에 많은 어려움을 겪고있다.행을 삽입 할 때 "데이터 예외 : 0으로 나누기"
<pre><code>
package Vegan;
import java.sql.Connection;
import java.sql.DriverManager;
public class connectionString {
static Connection connection = null;
public static Connection getConnection()
{
try
{
connection = DriverManager.getConnection("jdbc:ucanaccess://C:/Mo//MyDatabase1.accdb");
System.out.println("---connection succesful---");
}
catch (Exception ex)
{
System.out.println("Connection Unsuccesful");
}
return connection;
}
</pre></code>
<pre><code>
package Vegan;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DB {
private static ResultSet rs = null;
private static PreparedStatement ps = null;
private static Connection connection = null;
public DB() {
connection = connectionString.getConnection();
}
public void AddSupplier(String pw, String un, String sn, String cn, String ws, String pa, String city, String pv, String pc) throws SQLException
{
ps = connection.prepareStatement("INSERT INTO AccountTbl(StorePassword, Username, StoreName, ContactNo, Website, PhysAddress, City, Province, PostalCode) VALUES (?,?,?,?,?,?,?,?,?)");
ps.setString(1, pw);
ps.setString(2, un);
ps.setString(3, sn);
ps.setString(4, cn);
ps.setString(5, ws);
ps.setString(6, pa);
ps.setString(7, city);
ps.setString(8, pv);
ps.setString(9, pc);
ps.executeUpdate();
}
}
<pre><code>
package Vegan;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class SupplierReg extends javax.swing.JFrame {
private Object JOptionpane;
public SupplierReg() {
initComponents();
}
private void btnEnterActionPerformed(java.awt.event.ActionEvent evt) {
if ((txtAreaCode.getText().equals("")) || (txtCity.getText().equals("")) || txtContactNo.getText().equals("")
|| txtPassword.getText().equals("") || txtProvince.getText().equals("") || txtStoreName.getText().equals("") || txtStreetAddress.getText().equals("") || txtUsername.getText().equals("") || txtWebsite.getText().equals("")) {
JOptionPane.showMessageDialog(rootPane, "Please fill in all the information boxes");
} else {
try {
DB regDB = new DB();
regDB.AddSupplier(txtUsername.getText(), txtPassword.getText(), txtStreetAddress.getText(), txtStoreName.getText(), txtCity.getText(), txtContactNo.getText(), txtProvince.getText(), txtWebsite.getText(), txtAreaCode.getText());
} catch (SQLException ex) {
System.out.println(ex.getLocalizedMessage().toString());
}
setVisible(false);
new SupplierAbilityMenu().setVisible(true);
}
}
</pre></code>
내 값을 삽입 내가 말하는 오류 메시지가 :
<pre><code>
run:
---connection succesful---
UCAExc:::3.0.6 data exception: division by zero
BUILD SUCCESSFUL (total time: 1 second)
</pre></code>
임은 오류가 발생되는 말을하는 이유도 확실하지 않다 "부문 0으로 "하지만 데이터베이스에 숫자 필드로 된 필드가 없습니다.
편집 : http://www53.zippyshare.com/v/DMLjdpDw/file.html 링크 데이터베이스에 액세스하는
문제를 재현 할 수 없습니다. Access에서 데이터베이스를 열고 데이터베이스 압축 및 복구 작업을 시도하십시오. 문제가 지속되면 오류를 확실하게 재현 할 데이터베이스 파일 복사본에 대한 링크를 게시하는 것이 좋습니다. –
감사 링크를 추가했습니다. –