Sign in with
Sign up | Sign in
Your question

Java Data Base

Last response: in Applications
Share
January 14, 2012 2:58:23 PM

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:o dbc:D river={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);
}}}

More about : java data base

a b L Programming
January 15, 2012 4:03:35 AM

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.
m
0
l
!