Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Data Into MS Access Thru JDBC

Status
Not open for further replies.

sujitopics

Programmer
Oct 9, 2001
69
KR
Hi Friends

Can Anybody give Insertion Query to insert data into MS ACCESS Database thru JDBC Application

I am using the following Query

st.execute("insert into Testaccess values ('abcde','abcde')");

But the above query is not inserting data into ms access

Thanksinadvance

Yours
Rajesh
 
Hi,
There is nothing wrong with that query, unless u are setting autocommit to false and then not commiting the transaction after the insert. just put a try catch around that statement and then check if there are any sql exceptions being thrown. U could also use the Statement.executeUpdate(String query) method which is the one prescribed for insert, update and delete methods.

Hope this helps,
Reddy316
 
I got the Solution for my problem

The Code should be like this to insert the data into ms access 2000 thru jdbc

import java.sql.*;

public class TestAccess
{
public static void main(String[] args)
{
Connection con=null;;
Statement st=null;;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println(" Connected To Jdbc - Odbc Driver");
con= DriverManager.getConnection("Jdbc:Odbc:admin","","");
st=con.createStatement();
try
{
st.executeUpdate("insert into testaccess values ('aa','bb')");
System.out.println("Record Inserted");
}
catch (Exception create)
{
System.out.println("Exception in Inserting "+create);
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
st.close();
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top