plz give me one example and how to generate Driver of data base

mitmaya commented: how do use database for java +0

Dani AI

Generated

A short, practical update (the old bridge examples in this thread are now obsolete)

Many of the replies here (for example ’s JDBC-ODBC suggestion) reflect the approach used a decade or more ago. The Oracle-provided JDBC‑ODBC bridge was removed starting with Java SE 8, so those examples only work on very old JVMs. See the JDK 8 notes. (What's new in JDK 8)

Use a pure‑Java JDBC driver for Access instead. UCanAccess is a widely used, cross‑platform option that reads/writes .mdb and .accdb files and can be added via Maven/Gradle or by dropping its jars on the classpath. (UCanAccess home page)

Quick example (drop UCanAccess jars on the classpath or add the Maven artifact, then run database code off the UI thread):

try (Connection conn = DriverManager.getConnection(
         "jdbc:ucanaccess:///C:/path/to/db.accdb");
     PreparedStatement ps = conn.prepareStatement(
         "INSERT INTO Names(Name) VALUES (?)")) {
    ps.setString(1, textField.getText()); // get value from UI
    ps.executeUpdate();
}

Notes for and others using applets

  • Applets and the Java browser plugin are deprecated (JDK 9 deprecates Java deployment tech) and modern browsers removed plugin support (NPAPI), so applets are unreliable for shipping new code. (JDK 9 release notes, Chromium NPAPI deprecation)
  • Best practice: move DB operations to a server endpoint (servlet/REST API) and call that from the client. If you must run client-side DB code, do it in a background thread (SwingWorker) inside the button handler — prepare/execute inside that background task and always close resources (try-with-resources).
  • If you opt for Microsoft ODBC/OLEDB drivers instead of UCanAccess, be careful about 32/64‑bit driver/Java bitness and note Microsoft’s guidance that the Access Database Engine redistributable is not intended for server‑side, multi‑user server processes. (Microsoft Access Database Engine download page)

Troubleshooting: ensure all required jars are on the classpath, match Java/driver bitness, test the JDBC URL path (absolute), and run DB calls off the UI thread.

Recommended Answers

All 8 Replies

Database drivers (jdbc,odbc,.net...) are provided by database vendors or third party vendors and not generated. JDBC drivers are loaded into the JVM at runtime.

Please refer some books on JDBC Connectivity

to connect ms access with java
you have to datasource name

and write this code in ur program

Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:DSN name");
Statement stmt=con.createStatment();
ResultSet rs=stmt.executeQuery("select * from tablename");
while(rs.next())
{
System.out.println(rs.getSting("username"); //here username is the field name
}

the very first thing you need to do is to go to Control Panel --> adminstrative tools
then select the driver, and then your database

then you can write the code above mentioned in the reply above..
i guess that's pretty much it

Thanks for the help Guys, but I need to insert values in the database and I am using PreparedStatement to do this, the problem is I have created an applet but I am failed to know where do I need to put the connection or put the PreparedStatement.

For Example :
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Class A extends Applet {
{
public void init()
{
TextField t = new TextField();
Button b = new Button("SubmitRecords");
add(t);
add(b);
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Now this code create a simple applet with one textbox and button, I need to use insert statement to send the value of "t" in a field called "Names" in database on clicking the SubmitRecords Button. I am confused with the placement of the PreparedStatement and Connection Objects. Kindly help...!!

Thanks for the help Guys, but I need to insert values in the database and I am using PreparedStatement to do this, the problem is I have created an applet but I am failed to know where do I need to put the connection or put the PreparedStatement.

For Example :
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Class A extends Applet {
{
public void init()
{
TextField t = new TextField();
Button b = new Button("SubmitRecords");
add(t);
add(b);
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Now this code create a simple applet with one textbox and button, I need to use insert statement to send the value of "t" in a field called "Names" in database on clicking the SubmitRecords Button. I am confused with the placement of the PreparedStatement and Connection Objects. Kindly help...!!

Check this link ( <URL SNIPPED> ) for a reply to your question. Here you will find detailed description of how to connect to a SQL server database from a Java database application and pass embedded SQL queries. It describes how to create the connection string, pass parameters to the embedded SQL queries and stored procedures.

<FAKE SIGNATURE>

Thanks you very much, I am oblized.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.