我是Java初学者,对SQL命令知之甚少,说5或6个命令... 我尝试将我的Java项目与访问数据库" aman.accdb"在笔记本电脑中使用ODBC .. 数据库有一个名为" tab"的表。 我正在使用带有Java JDK的Windows 7 64位PC,其中安装了64位。我也使用ms office 2013,它也是64位产品。
当我执行代码时出错" java.sql.SQLException找不到合适的驱动程序jdbc:odbc:man" 我发布了示例代码,导致下面的错误。我删除了不需要的行,例如布局设置和所有为页面运行的行。
请提供解决方案!
package sample;
import java.sql.*;
import javax.swing.JOptionPane;
public class als extends javax.swing.JFrame {
public als() throws SQLException {
initComponents();
try
{
con=DriverManager.getConnection("jdbc:odbc:man") ;
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Check");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
st=con.createStatement();
String s=("insert into tab ('senthil',12)");
st.execute(s);
JOptionPane.showMessageDialog(rootPane,"Saved");
this.setVisible(false);
}catch(Exception e)
{
JOptionPane.showMessageDialog(rootPane,e);
}
}
static Connection con;
static Statement st;
static ResultSet rs;
private javax.swing.JButton jButton1;
}
我发现这个问题出现在64位OS oly中。如果我安装32位操作系统,这不会发生。
注意:我收到的错误是一个例外,我通过构造函数catch()
中als()
部分的消息框显示。
答案 0 :(得分:2)
我正在使用JDK 1.8.0
JDBC-ODBC Bridge已从Java 8中删除。请考虑使用UCanAccess JDBC驱动程序。详情。见
答案 1 :(得分:0)
试试这个,我相信它,因为你没有指定驱动程序。这适用于MS Access
数据库。
public als() throws SQLException {
initComponents();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:man") ;
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}