torres

Distinguished
Feb 2, 2010
7
0
18,510
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 = "jdbc:eek:dbc:Driver={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);
}}}

 

PhilFrisbie

Distinguished
I have never used Access with Java, but I can tell you to only use Access for single-user applications. In other words, DO NOT try to use this on a web server where multiple users might be accessing the Access database at once. An Access database is easily corrupted in a multi-user environment.