Hi i just started with java and Microsoft acces and i am a little stuck on how to connect Java with Access 2010.I think it have something to do with the name of the file.Soccer.accdb while the other site and books use the .mdb.
CODE
public static void main(String[]args)
{
new Procesor();
}
class UpdateClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{}
try
{
String dataSourceName = "./Soccer.mdb";
String database = "jdbcdbcriver={Microsoft Access Driver(*.mdb)};DBQ=";database +=database + dataSourceName.trim()+";DriverID = 22;READONLY=true}";
Connection conn = DriverManager.getConnection(database,"","");
System.out.println("Connected");
PreparedStatement ps = conn.prepareStatement("INSERT INTO Games(Sport)VALUES(?)");
ps.setString(1,procesorTextField.getText());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Record inserted succesfully");
conn.close();
}
catch(SQLException sqle)
{
JOptionPane.showMessageDialog(null,"Connection Failed");
}
}
}
class ExitButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}}}
CODE
public static void main(String[]args)
{
new Procesor();
}
class UpdateClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{}
try
{
String dataSourceName = "./Soccer.mdb";
String database = "jdbcdbcriver={Microsoft Access Driver(*.mdb)};DBQ=";database +=database + dataSourceName.trim()+";DriverID = 22;READONLY=true}";
Connection conn = DriverManager.getConnection(database,"","");
System.out.println("Connected");
PreparedStatement ps = conn.prepareStatement("INSERT INTO Games(Sport)VALUES(?)");
ps.setString(1,procesorTextField.getText());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Record inserted succesfully");
conn.close();
}
catch(SQLException sqle)
{
JOptionPane.showMessageDialog(null,"Connection Failed");
}
}
}
class ExitButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}}}