Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert data to MS Access using JAVA

 
Jeremy Ray Dean
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm doing a project for an Info. Sys. Class, and we need to be able to insert values into tables in MS Access using Java. We've already got the JDBC-ODBC bridge and are able to view Tables and Queries through our applet, but I can't quite figure out how to insert new data into the tables. Anyone out there know of some good Java-to-MS SQL links???
Thanks,
-Jeremy
 
Amit More
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code which will insert the values in to access database table 'Emp' :
-----------------------------------------------------
Connection con;
PreparedStatement ps = null;
Statement stmt = null;
String name;
int sal;
name = request.getParameter("txtName");
sal = Integer.parseInt(request.getParameter("txtSal");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con=DriverManager.getConnection("jdbc dbc:Amit");

String sql = "INSERT INTO Emp(Name, Salary) VALUES (?,?)";
ps = con.prepareStatement(sql);
stmt = con.createStatement();

ps.setString(1, name);
ps.setInt(2, sal);
ps.executeUpdate();
-----------------------------------
Amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic