希望各位好友在百忙之中看下小弟的這個Java問題

來源:互聯網
上載者:User
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 由於將在索引、 主關鍵字、或關係中建立重複的值,請求對錶的改變沒有成功。 改變該欄位中的或包含重複資料的欄位中的資料,刪除索引或重新定義索引以允許重複的值並再試一次。

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbt1)
{
Connection con=null;
PreparedStatement st=null;
ResultSet re=null;
try{
//載入驅動
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//得到串連(串連到資料來源)
con=DriverManager.getConnection("jdbc:odbc:STUDB");
//建立語句(發送SQL語句得到資料庫)
String stu1=" insert into student1 values(?,?,?,?,?)";
st=con.prepareStatement(stu1);
st.setString(1, jtf1.getText());
st.setString(2, jtf2.getText());
st.setString(3, jtf3.getText());
st.setString(4, jtf4.getText());
st.setString(5, jtf5.getText());

st.executeUpdate();
this.dispose();

}catch(Exception c)
{
c.printStackTrace();
}finally{
try{
if(re!=null) re.close();
if(st!=null) st.close();
if(con!=null) con.close();
}catch(Exception c)
{
c.printStackTrace();
}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.