JDBC & MS Access

The following code is from "Java 2 for Dummies":
import java.sql.*;
public class CreateTable
public static void main(String args [])
throws SQLException, ClassNotFoundException
Connection connection;
     Statement statement;
     Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver");
     connection = DriverManager.getConnection
("jdbc:odbc:AccountDatabase");
     statement = connection.createStatement();
     statement.executeUpdate(
     "create table ACCOUNTS " +
     " (NAME VARCHAR(32) NOT NULL PRIMARY KEY, " +
     " ADDRESS VARCHAR(32), " +
" BALANCE FLOAT) ");
     statement.executeUpdate
     "insert into ACCOUNTS values " +
     "('Barry Burd','222 Cyberspace Lane', 24.02) "
     statement.executeUpdate
     "insert into ACCOUNTS values " +
"('Jane Public','111 Consumer Street',55.63)"
statement.close();
connection.close();
The code compiles with no errors but I get the following message when executing the code:
C:\testbed>java CreateTable
Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Microsoft Acc
ess 97 Driver] Syntax error in CREATE TABLE statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
at CreateTable.main(CreateTable.java:18)
=============================================
I use the following steps to create the data source:
1. In Win 98 I choose Start....Settings....Control Panel
2. Double-click Data Sources (ODBC).
3. In the ODBC Data Source Administrator, select DSN tab
4. Then Add
5. In Create New Data Source, select Microsoft Access Driver
6. Click Finish.
7. Type AccountDatabase in Data Source Name field.
8. Type anything in Description field.
9. Click the Create button.
10. Browse directory where I want your database file to be created and
type AccountFile the Database Name field.
11. Click OK.
Any clues, why I get the error message?
Thanks,
George

Thanks,
Based on what you told me, I did some
research into Access 97 and
its implementation of the
SQL "CREATE TABLE" statement.
I substituted
"create table ACCOUNTS
(NAME VARCHAR(32) NOT NULL CONSTRAINT
MyFieldConstraint PRIMARY KEY,
ADDRESS VARCHAR(32), BALANCE FLOAT)"
for
"create table ACCOUNTS
(NAME VARCHAR(32) NOT NULL PRIMARY KEY,
ADDRESS VARCHAR(32), BALANCE FLOAT)"
Now it works. It seems I needed to include
the CONSTRAINT command. I don't know why
but I'll have to further research. I
guess it worked for you, njrajesh, because your later
version of Access implements SQL such that
it accepts the original "create table."
Thanks, njrajesh and DrClap, very much for your help.
George

Similar Messages

  • Use JDBC to Access XML Documents in Oracle XML DB

    Hi folks,
    From the Oracle XML DB Developer's Guide 10g Release 1 (10.1) Chapter 12 Java API for XMLType, it show several examples for how java application use JDBC to access xml in XMLDB:
    1. use getOPAQUE() on XMLTYPE table/column and then call XMLTYPE.createXML();
    2. use getCLOBVal()/getStringVal()/getBLOBVal() in SQL statement;
    3.use getObject on the result and cast directly to XMLType;
    Among these 3 options, which is supposed to be the fastest way? Any difference between thin and oci?
    I have run some tests about that and the result is the second option (with thin driver) is the fastest. It surprises me because I think oci should be faster than thin. Does the result make sense?
    Thanks.

    Have you tried to trace your sessions to see how much work is happening? Traces should give you quantifiable information on exact times and access paths to the data.
    Below is a link to an O'Reilly book excerpt on Java programming with JDBC. Slightly data, but may be of assistance.
    http://www.onjava.com/lpt/a//onjava/excerpt/oraclejdbc_19/index.html

  • JDBC MS Access--- cannot extract entry with null value with data type Meta

    I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
    The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
    Any advice will be appreciated! thanks!
    Following are the table description and JDBC code:
    test table has the following attributes:
    Field name Data Type
    name Text
    label Memo
    table contents:
    name label
    me null
    you gates
    Code:
    String query = "SELECT name, label FROM test where name like 'me' ";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next())
    String name = rs.getString("name");
    rs.getString("val");
    String label = rs.getString("label");
    System.out.println("\t"+name+"\t"+label);
    catch (SQLException ex)
    System.out.println(ex.getSQLState());
    System.out.println(ex.getErrorCode());
    System.out.println("in sqlexception");
    output:
    C:\Temp\SEFormExtractor>java DBTest
    yet SELECT name, label FROM test
    null
    0
    in sqlexception

    The question is how to extract null entry with data type memo?Okay, what you need to do is this:
    if (rs.getString("val") == null)
      // do something
    }This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception.

  • Regarding File to JDBC/MS Access database

    Hi all,
    I am trying to insert some values in to MS access database table.I kept the .mdb file in the local PI folder.I am getting connection error
    com.sap.aii.af.service.util.concurrent.ResourcePoolException: Unable to create new pooled resource: DriverManagerException: Cannot establish connection to URL 'jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=//test/data/input/Employee.mbd': SAPClassNotFoundException: jdbc.odbc.JdbcOdbcDriver
    i have given the configuration as:
    JDBC Driver:   jdbc.odbc.JdbcOdbcDriver
    Connection:  jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=//test/data/input/Employee.mbd
    Please give me some pointers.
    Regards,
    Anika

    Hi Anika,
    Also please check for :
    You can set the configuration as following:-
    JDBC Driver : sun.jdbc.odbc.JdbcOdbcDriver
    Connection : jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= Full Path of DB file;
    eg of full path:D:\USERS\Employee\employee.mdb
    Please go through these steps: (Assuming you are working on Windows)
    1) An ODBC driver for your database must be installed on the Windows computer running the application server.
    Check if there's an ODBC driver for MS Acess on the application Server.
    2) To connect through an ODBC driver, you must install the Sun JDBC-ODBC Bridge driver on the Windows computer running the application server. The driver comes with the Sun Java 2 SDK, Standard Edition, for Windows.
    Also there is another point.
    sun.jdbc.odbc.JdbcOdbcDriver
    This driver is a part of the JDK kit and so, you need not install the driver on your XI server. Check the SAP Note JDBC FAQ for this info.
    3)Define a DSN on the Windows system hosting your application server.
    4)These parameters you need to give while configuring the JDBC receiver adapter channel
    Regards
    joel
    Edited by: joel trinidade on Mar 26, 2009 12:45 PM

  • JDBC, Oracle: access denied

    I can load Oracle driver
    Class.forName("oracle.jdbc.driver.OracleDriver");
    But in this string:
    String url = "jdbc:oracle:thin:@195.52.61.6:1521:ORCL";
    java.sql.Connection con = java.sql.DriverManager.getConnection(url, "SCOTT", "TIGER");
    happens exception:
    java.security.AccessControlException: access denied (java.net.SocketPermission 195.52.61.6:1521 connect,resolve)
    I have found in this forum many same messages. Can anybody explain problem?

    Are you using an applet?

  • JSP using jdbc to access mdb

    Done ...
    User DSN and System DSN Add. Select Microsoft Access Driver (*.mbd) and data source name is aa
    in JSP ..
    <%@ page import="com.thinweb.sql.*" %>
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c1 = DriverManager.getConnection("jdbc : odbc : aa","",""); [no spacing]
    Error: 500
    Location: /gone.jsp
    Internal Servlet Error:
    javax.servlet.ServletException: No suitable driver
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
    at _0002fLoginM_0002ejspLoginM_jsp_10._jspService(_0002fLoginM_0002ejspLoginM_jsp_10.java:181)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
    at org.apache.tomcat.core.Handler.service(Handler.java:286)
    at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
    at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
    at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
    at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
    at java.lang.Thread.run(Thread.java:484)
    Root cause:
    com.thinweb.sql.SQLException: No suitable driver
    at com.thinweb.sql.DriverManager.getConnection(Unknown Source)
    at com.thinweb.sql.DriverManager.getConnection(Unknown Source)
    at _0002fLoginM_0002ejspLoginM_jsp_10._jspService(_0002fLoginM_0002ejspLoginM_jsp_10.java:123)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
    at org.apache.tomcat.core.Handler.service(Handler.java:286)
    at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
    at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
    at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
    at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
    at java.lang.Thread.run(Thread.java:484)

    You must have the JdbcOdbcDriver.class in your classpath.

  • Jdbc ms access problem

    hi,
    i am trying to do a simple query to update database information in
    ms access running on the same machine using XP. i have been testing it and after inserting about 200 records it slows down to almost a standstill.
    here is my code:
    import java.io.*;
    import java.sql.*;
    import javax.swing.*;
    public class AutomatedUpdate
    private Connection conn;
    private Statement statement;
    private RandomAccessFile custFile;
    //private RandomAccessFile ordersFile;
    public AutomatedUpdate()
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:labelweb_db");
    //pre-generated sql statements to do db insert.
    custFile = new RandomAccessFile("test.txt", "r");
    //ordersFile = new RandomAccessFile("tbl_Orders.sql", "r");
    String delCustQuery = "Delete * From tbl_Customers";
    //String delOrdersQuery = "Delete * From tbl_Orders";
    statement = conn.createStatement();
    statement.execute(delCustQuery);
    // statement = conn.createStatement();
    // statement.executeQuery(delOrdersQuery);
    catch(Exception e){e.printStackTrace();}
    dumpData(custFile);
    //dumpData(ordersFile);
    System.exit(0);
    public void dumpData(RandomAccessFile file)
    StringBuffer buf = new StringBuffer();
    String text;
    String query;
    try
    while((text = file.readLine()) != null)
    if(text.startsWith("#") || text.equals(""))
    continue;
    statement = conn.createStatement();
    query = text.substring(0,text.length()-1);
    for(int i = 0; i < 10000; i++)
         if(i % 10 == 0)
              System.out.println(i);
    statement = conn.createStatement();
    statement.execute(query);
    conn.close();
    catch(Exception e){e.printStackTrace();}
    public static void main(String[] args)
    AutomatedUpdate automatedUpdate1 = new AutomatedUpdate();
    Any thoughts / suggestions would be greatly appreciated.
    Thanks in advance,
    Aaron.

    first there are a few screwy things about the code you posted...
    public void dumpData(RandomAccessFile file){
      StringBuffer buf = new StringBuffer(); //ooookkkkay
      String text;
      String query;
      try{
        while((text = file.readLine()) != null){
          if(text.startsWith("#") || text.equals(""))
            continue;
          statement = conn.createStatement();
          query = text.substring(0,text.length()-1);
          for(int i = 0; i < 10000; i++){
            if(i % 10 == 0){
              System.out.println(i);
            }// closing the if
            statement = conn.createStatement();// oh dear why is this here?
            statement.execute(query);
          }// closeing the for
          conn.close();// not good still inside the while
        }// closing the while
      }catch(Exception e){e.printStackTrace();}// closing the try/catch block
    }here are my comments.
    1) What is the StringBuffer buf for? You initialize it but never use it.
    2) You are inserting the same query 10000 times on each
    pass. See how the createStatement and execute blocks are inside the for
    loop. I somehow don't think this is what you are intending.
    3) You are also closing the connection each time you go through so if
    your program ever got to a second query it would blow up any. You should
    probably close you connection in the same place you create it but after
    the method call.
    4) You are not explicitly closing any statements and since you are
    making so many this can't help.
    so here is my revision of your method.
    public void dumpData(RandomAccessFile file)throws IOException, SQLException{
      String text;
      String query;
      Statement s = conn.createStatement(); 
      while((text = file.readLine()) != null){
        if(text.startsWith("#") || text.equals(""))
          continue;
        query = text.substring(0,text.length()-1);
        s.execute(query);
      s.close();
    }so why don't you give this a while and if you are still having problems
    we will see what we can do.

  • Toplink JPA: jdbc connection access required

    I have a strong reason why direct access to the connections used by Toplink JPA is required: for each connection I need to execute
    - a "set role" to grant permissions,
    - "set lock mode" to prevent hangups,
    - "set isolation" to get the correct transaction type,
    - possibly a "set explain on" to get query costs info,
    - and a "set constraints all deferred" to have constraints checked at commit time, not earlier.
    Can the Toplink pooling mechanism be replaced?

    You can use either an external data source from your container or an JDBC data source for that matter but you cannot replace the internal connection pool. Although one option may be to use a wrapped connection pool of your own I would first recommend looking at the SessionEventListener callbacks. Implementing this interface and registering it using a SessionCustomizer (persistence unit property) would allow you to be notified and get access to the JDBC connection when acquired and released from either pooling mechanism.
    Here is an example:
    public class JDBCConnectionListener extends SessionEventAdapter implements SessionCustomizer {
         * This method is used when this class is configured as the session customizer
         * in the persistence unit properties.
        public void customize(Session session) {
            session.getEventManager().addListener(this);
         * This event is raised after a connection is acquired from a connection pool.
        public void postAcquireConnection(SessionEvent event) {
            DatabaseAccessor da = (DatabaseAccessor)event.getResult();
            Connection con = da.getConnection();
            PreparedStatement statement;
            try {
                event.getSession().log(SessionLog.FINE, SessionLog.SQL, "POST-ACQUIRE> SELECT SYSDATE FROM DUAL");
                statement = con.prepareStatement("SELECT SYSDATE FROM DUAL");
                ResultSet rs = statement.executeQuery();
                rs.close();
            } catch (SQLException e) {
                // TODO
         * This event is raised before a connection is released into a connection pool.
        public void preReleaseConnection(SessionEvent event) {
    }Doug

  • JDBC locking access db

    i can create the table from jframe. i can open the program and instantly insert records, but if i insert a table, then try and insert records i get sqlexception error saying database is locked by othe process and I DON'T have Access open or another instance of this program. but it does seem to write the new records. any help would be great. fully runnable code presuming you setup Coffee DSN. it locks on line 180 which is part of the tableExistsCreateNew method where i try and drop the table.
    mike
    screen output.
    A Table already exists with data
    Old table was deleted.
    New table was created successfully
    Table has data records, they will be deleted
    An empty table exists
    Error in creatingtable after dropping.Records were created successfully
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.swing.JTextPane;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    * CoffeeDBAdmin.java
    * Created on July 20, 2004, 1:33 PM
    * @author Participant5
    public class CoffeeDBAdmin extends javax.swing.JFrame {
    /** Creates new form CoffeeDBAdmin */
    Connection conn;
    String message;
    public CoffeeDBAdmin() {
    initComponents();
    createConnection();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {//GEN-BEGIN:initComponents
    jTextPane1 = new javax.swing.JTextPane();
    jMenuBar1 = new javax.swing.JMenuBar();
    MenuDatabase = new javax.swing.JMenu();
    CreateTable = new javax.swing.JMenuItem();
    Insert = new javax.swing.JMenuItem();
    Retrieve = new javax.swing.JMenuItem();
    Exit = new javax.swing.JMenuItem();
    setTitle("CoffeeDBAdmin");
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    jTextPane1.setMinimumSize(new java.awt.Dimension(375, 200));
    jTextPane1.setPreferredSize(new java.awt.Dimension(375, 200));
    getContentPane().add(jTextPane1, java.awt.BorderLayout.CENTER);
    MenuDatabase.setText("Database");
    MenuDatabase.setActionCommand("MenuDatabase");
    CreateTable.setText("Create Table");
    CreateTable.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    CreateTableMouseReleased(evt);
    MenuDatabase.add(CreateTable);
    Insert.setText("Insert");
    Insert.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    InsertMouseReleased(evt);
    MenuDatabase.add(Insert);
    Retrieve.setText("Retrieve");
    Retrieve.setActionCommand("Retrieve");
    Retrieve.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    RetrieveMouseReleased(evt);
    MenuDatabase.add(Retrieve);
    Exit.setText("Exit");
    Exit.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    ExitMouseReleased(evt);
    MenuDatabase.add(Exit);
    jMenuBar1.add(MenuDatabase);
    setJMenuBar(jMenuBar1);
    pack();
    }//GEN-END:initComponents
    private void ExitMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMouseReleased
    // TODO add your handling code here:
    exitRoutine();
    }//GEN-LAST:event_ExitMouseReleased
    public void createConnection()
    try{
    //load JDBC ODBC driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //setup the connection
    String url = "jdbc:odbc:Coffee";
    conn = DriverManager.getConnection
    (url, "myLogin", "myPassword");
    catch (Exception e)
    message = "DSN Error.";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    //e.printStackTrace();
    public void createTable()
    try
    Statement stmt = conn.createStatement();
    //jTextPane1.setText(null);
    //stmt.executeUpdate("DROP TABLE COFFEES");
    stmt.executeUpdate("CREATE TABLE COFFEES " +
    "(COFFEE_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
    "SALES INTEGER, TOTAL INTEGER)");
    System.out.println();
    //jTextPane1.setText(null);
    stmt.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    message = "Database Error";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    catch (SQLException tableExists)
    //System.out.println("Table already exists");
    this.tableExistsCreateNew();
    public void tableExistsCreateNew()
    try{
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Coffee_Name, " +
    "Price FROM COFFEES");
    if((rs.next() == true))
    message = "A Table already exists with data\n";
    else
    message = "An empty table exists\n";
    rs = stmt.executeQuery("SELECT Coffee_Name, Price " +
    "FROM COFFEES");
    jTextPane1.setText(jTextPane1.getText() + "\n" + message);
    stmt.executeUpdate("DROP TABLE COFFEES");
    jTextPane1.setText(jTextPane1.getText() +
    "Old table was deleted.\n");
    stmt.executeUpdate("CREATE TABLE COFFEES " +
    "(COFFEE_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
    "SALES INTEGER, TOTAL INTEGER)");
    jTextPane1.setText(jTextPane1.getText() +
    "New table was created successfully\n");
    //this.createRecords();
    stmt.close();
    //rs.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    jTextPane1.setText(jTextPane1.getText() + "\nDatabase Error.");
    JOptionPane.showInternalMessageDialog(jMenuBar1,"Database" +
    " Error");
    catch(Exception e)
    System.out.println("\nerror in creating table after dropping\n");
    e.printStackTrace();
    //System.exit(0);
    jTextPane1.setText(jTextPane1.getText() + "\nError in creating" +
    "table after dropping.\n");
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    "Error in creating table after dropping.\n");
    public void createRecords()
    try
    { Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT " +
    "Coffee_Name, Price " + "FROM COFFEES");
    if(rs.next() == false)
    jTextPane1.setText(jTextPane1.getText() +
    "\nTable has data records, they will be " +
    " deleted\n\n");
    //stmt.executeUpdate("DROP TABLE COFFEES");
    tableExistsCreateNew();
    stmt.executeUpdate("INSERT INTO COFFEES " +
    "(Coffee_Name, SUP_ID, Price) " +
    "VALUES ('Colombian', 101, 7.99)");
    stmt.executeUpdate("INSERT INTO COFFEES "+
    "(Coffee_Name, SUP_ID, Price) " +
    "VALUES ('French_Roast', 49, 8.99)");
    jTextPane1.setText(jTextPane1.getText() + "Records" +
    " were created successfully\n");
    //rs.close();
    stmt.close();
    catch (Exception e)
    //System.out.println("Error in creating records");
    //e.printStackTrace();
    //System.exit(0);
    message = "The Table you requested does not exist.";
    JOptionPane.showInternalMessageDialog(jMenuBar1,message);
    public void printRecords()
    try
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Coffee_Name, Price " +
    "FROM COFFEES");
    jTextPane1.setText("Coffee Prices\n");
    //System.out.println("Coffee Prices");
    while(rs.next())
    jTextPane1.setText((jTextPane1.getText() + rs.getString(1)
    + " " + rs.getDouble(2) + "\n" ));
    // System.out.println(rs.getString(1) + " " +
    // rs.getDouble(2) + "\n" );
    //rs.close();
    stmt.close();
    //conn.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    message = "Database Error";
    jTextPane1.setText(jTextPane1.getText() + "\n" +
    message);
    JOptionPane.showInternalMessageDialog(jMenuBar1,"You " +
    "cannot retrieve" + "records from a null or " +
    "uncreated table");
    //System.exit(0);
    catch (Exception e)
    //message = "Error in printing records";
    jTextPane1.setText(jTextPane1.getText() +"\n" +
    message);
    //System.exit(0);
    e.printStackTrace();
    //JOptionPane.showInternalMessageDialog(jMenuBar1,"You cannot retrieve" +
    //"records from a null or uncreated table");
    public void exitRoutine()
    try{
    conn.close();
    dispose();
    System.exit(0);
    catch (Exception e)
    message = "error closing connection";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    //e.printStackTrace();
    private void RetrieveMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RetrieveMouseReleased
    // TODO add your handling code here:
    printRecords();
    }//GEN-LAST:event_RetrieveMouseReleased
    private void InsertMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_InsertMouseReleased
    // TODO add your handling code here:
    createRecords();
    }//GEN-LAST:event_InsertMouseReleased
    private void CreateTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateTableMouseReleased
    // TODO add your handling code here:
    createTable();
    }//GEN-LAST:event_CreateTableMouseReleased
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
    dispose();
    System.exit(0);
    }//GEN-LAST:event_exitForm
    * @param args the command line arguments
    public static void main(String args[]) {
    new CoffeeDBAdmin().show();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem CreateTable;
    private javax.swing.JMenuItem Exit;
    private javax.swing.JMenuItem Insert;
    private javax.swing.JMenu MenuDatabase;
    private javax.swing.JMenuItem Retrieve;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

    Are you releasing your connections appropriately?

  • RFC to JDBC ( Ms Access )

    Hi
    I am working on RFC to JDBC scenario.
    I have done the configuration as per
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417700)ID2063057750DB01438375578713251689End?blog=/pub/wlg/2590
    I am getting the following error message
    "com.sap.aii.af.ra.ms.api.DeliveryException: JDBC Adapter configuration not initialized: null"
    Pls let me know, your suggestions on the same
    Regards
    Madhan D

    Hi Madhan,
      I think its problem with your JDBC driver deployment. So pls cross-check.
    1.Check whether the JDBCAdapter is Activated.
    2.Check if any firewalls are there frm client side and open
    3.Check the password used to connect the Database is correct one.
    4. Please check your connection string in ID whether it's correct.
    If all these are fine..ask your basis guys to do a complete CPACache refresh and then rerun your scenario.......if still the error is same, then restart your XI J2EE engine and ask your basis guys to see if there is any error in your J2EE startup log..........
    Also you may check if the DB was down (e.g. for maintenance). Sometimes reconnection issues appear in such cases. Try to stop and start the channel.
    Please use this note to check if the JDBC drivers have been installed correctly and you can access the database.
    1085539 XI JDBC/FTP connection Test and XML Validation Application.
    Regds,
    Pinangshuk.

  • Missing parameter in Jdbc Ms access connection

    hi everybody?
    how are you doing?
    i have a small problem
    i hope helps me get rid of it
    the problem is:
    i wrote a servlet which makes a connection to an MS access database and retreives a data.
    I am having an exception saying that one parameter is missing ?Can someone tell me what is wrong with this code? Thanks :)
    here is the code snippet:
    import java.io.*;
    import java.sql.*;
    public class dbconn {
    Connection con = null;
    String user="yilmaz";
    String username,userpassword="";
    String sql="select pass from members where user='yilmaz'";
    Statement st=null;
    ResultSet rs=null;
    //public String main(St
    public String connectDatabase() {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:focus&userid=&password=");
    st=con.createStatement();
    rs=st.executeQuery(sql);
    while(rs.next()) {
    username=rs.getString(1);
    userpassword=rs.getString(2); }
    return userpassword;
    } catch (SQLException e) {
    System.out.println("Could not connect database :"+e.getMessage());
    return userpassword;
    catch (IOException ioe) {System.out.println(" IOexception "+ioe.getMessage()); }
    public void closeConnection() {
    try {
    if (con != null)
    con.close();
    } catch (Exception e){
    System.out.println("error: can not close database connection"+e.getMessage());

    Use
    e.printStackTrace()
    This will tell you the line that the error occurs on.
    I would suspect that the error is on the getConnection() line. I have never seen '&' used in a connection string. I have seen ';'. And usually user/pwd a just passed in as argements to the getConnection() rather than putting it in the connection statement.

  • JDBC with Access

    I've started reading on JDBC in a book I've had and I truly don't have a clue what it's talking about on how to set up the driver. But one thing it says is that they recommend not using the driver the Java 2 SDK comes with, and even more strongly recommends not using it with a desktop database such as Access. Seeing that access is the only database I know how to use, can someone direct me to the right/best driver and how/where I can download it?
    Also, does this mean that everyone that uses my program has to have the driver for it to work?

    I've started reading on JDBC in a book I've had and I
    truly don't have a clue what it's talking about on how
    to set up the driver. All that you have to do is to have the driver class somewhere in your classpath. For example, with Oracle, the driver classes are shipped in the file classes12.zip (for 8i, at least...). To get the JDBC DriverManager to see them, you just need to add this file to your classpath.
    Of course, every driver may have different parameters/settings for actually getting a connection. Consult the docs for the driver on the specifics.
    But one thing it says is that
    they recommend not using the driver the Java 2 SDK
    comes with, and even more strongly recommends not
    using it with a desktop database such as Access.This comes from the JDBC docs from Sun, which may be useful for you to look at (they come with the standard API documentation under the "Enterprise Features" heading). This page has the caveat about the driver shipped with the SDK and also explains things like the differences between the different driver types and such. I would recommend you taking a look at this.
    Seeing that access is the only database I know how to
    use, can someone direct me to the right/best driver
    and how/where I can download it?Have you tried a google search on this?
    Also, does this mean that everyone that uses my
    program has to have the driver for it to work?Yes. However, if you package your app in a jar then you can put the dependent drivers in the jar file along with your app classes and then configure the jar file with a main class to execute with and a classpath that contains these classes so that end users don't have to worry about any of these details.
    Cheers,
    Nathan

  • JDBC & Microsoft Access

    Can someone point me to an example of using MS Access through JDBC? I'm hoping to find an example which doesn't rely on the DSN being already created. In Visual Basic Access is a 'native driver', meaning I don't need a DSN for it. Can I get JDBC to do this? Does Java have a 'native driver' itself?
    Thanks!

    I do believe the only way of doing this is through native code, using system calls, etc... If your familiar with vc++ the task, Im assuming is probably not all to difficult. Codeguru.com hosts a very nice forum for vc++ and Im sure some one there could point you in the right direction. Once you have a small native application to handle that task, youdeither run it directly from java, or use jni... In my opinion this more trouble than its worth and furthermore destroys portability...
    Currently working on a database program and wanting to be able to deliver it to the desktop, I have opted to use HSQL a pure java opensource database as a default, and well the option of configuring any other database the user desires... Youd probably want to talk to some windows programmers as they will most likely be able to provide you with info you need to tackle the problem.

  • Update problems with jdbc on access db too

    hi..
    i have a strange problem with updating a record in ms-access - db by using jdbc.
    my program creates a "correct??" update-statement but i get an error-message: errorcode:3144.. syntaxerror in update-statement or something like that..
    thats the statement that my program creates:
    update maX2 set m1='super',set m2='hallo' where id=2
    java-code:
    Statement stmt = con.createStatement();
    stmt.executeUpdate(... the update-statement ...);
    does anybody know why i get this errormessage?

    Your statemente should be:
    update maX2 set m1='super', m2='hallo' where id=2
    HTH

  • JDBC adapter access to iSeries DB files in libraries

    Hello,
    We try to connect to an AS400 iSeries system via JDBC adapter!!! (not a typical scenario I think!)
    The files (so called by IBM but we identify them as tables in our understanding ) are stored in libraries.
    The question is how to add this library (like a path?) into JDBC adapter and interface description.
    Adapter:
    JDBC Driver: <driver name>
    Conenction: <physical address of iSeries DB>
    LogIn data: xxx
    Interface description:
    MESSAGE
        STATEMENT   = []
        TABLENAME
                ACTION    = select
                TABLE      =  DBNAME.TABLENAME
    The interface description is from another successful implementation on an ORACLE DB.
    I think the table definition should contaion the library like
      <DBNAME>.<LIBRARY>.<TABLENAME>
    separated by dots!
    I am not sure. So can anyone correct or agree?
    Currently we are not ready for a first try because the driver installation is next week.
    But it would help to know what we have to do instead of spending possibly a lot of time for trial and error.
    Kind Regards
    Dirk
    Of course, helpful answers are valued by points!

    I don't know this mechanism of high availability with 2 IP, but if you really have 2 hostname you should think to a method to switch from a node to the other in easy way, deactivating one and activating the other (for instance with the <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/45/0c86aab4d14dece10000000a11466f/frameset.htm">Controlling a Communication Channel Externally</a>)
    I suggest you to verify how it will be in production instance: real cluster ? switch over ? virtual IP ?
    Regards,
    Sandro

Maybe you are looking for

  • What do I do with the results of EtreCheck if I am trying to be proactive? embarrassed grin Can anyone help?

    Good morning. This is my machine:  EtreCheck version: 1.9.12 (48) Report generated July 31, 2014 at 6:52:07 AM EDT Hardware Information:   iMac (21.5-inch, Mid 2010) (Verified)   iMac - model: iMac11,2   1 3.2 GHz Intel Core i3 CPU: 2 cores   16 GB R

  • Batch creation of 2ndary cost elements

    Hi Experts, Is there a program that will allow me to create secondary elements in a batch? I can only create secondary cost elements one by one right now. Thanks!

  • Problem in running job from OEM

    I have registered JOB with OEM using TCL script from warehouse builder. I login to OEM and it shows me one job in JOB library. Now i submit this job. It keeps on showing status submitting on the Active jobs tab. It does not do anything Thanks in adva

  • Write an ABAP to build a hierarchy

    Hi, I have a table TVBVK that is required to be read off from to create a hierarchy. The fiedl VKBUR is used to create a root node and the field VKGRP is then to be used to create the leaves. Has anyone written a program to read from this table and t

  • Ios8 Photo - Apple come on....

    Wow - a nice IOS8 for lots of stuff - but what happened when you reworked the Photo App?? Bring back the function of Camera Roll and Photostream! (would also be nice to have my pictures back which I lost from Camera Roll after the upgrade!!) Nice ide