Here we are using third party jar for creating Access DB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.Types; import com.healthmarketscience.jackcess.*; public class access extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,java.io.IOException { resp.setContentType( "text/html" ); PrintWriter out = resp.getWriter(); try { Database db = Database.create( new File( "newDB.mdb" )); Column a = new Column(); a.setName( "Employee#" ); a.setSQLType(Types.INTEGER); Column b = new Column(); b.setName( "Employee Name" ); b.setSQLType(Types.VARCHAR); db.createTable( "NewTable" , Arrays.asList(a, b)); Table newTable = db.getTable( "NewTable" ); newTable.addRow( new Object[] { 23401 , "Ram" }); newTable.addRow( new Object[] { 23402 , "Krishna" }); out.println(Database.open( new File( "newDB.mdb" )).getTable( "NewTable" ).display()); } catch (Exception e) { e.printStackTrace(); } } } |