Please help me get started with Databases...

I've spent all day moving from one tutorial to the other trying to figure out how to use a Database with Java. I haven't found anything that explained things basic enough for me to understand, however, I did download and install MDAC 2.8 which was suggested in on one of the sites and I also have MS Access to work with for creating the database. Can somebody please explain what I need to do in order to access a database from my program in simple, easy to follow, steps?
Also I have a small question about .requestFocus();In my program I have a Radio button called Format1 and a text area called textArea. I set Format1 to be selected using the following code: Format1.setSelected(true); and I attempted to make the cursor start inside the text area with: textArea.requestFocus(); Currently, when I start the program, Format1 has the focus instead of textArea. How can I make the cursor start at the end of the text inside of textArea everytime I start my program?

Try this:
package be;
import java.sql.*;
import java.util.*;
public class DataConnection
    public static final String DEFAULT_DRIVER   = "sun.jdbc.odbc.JdbcOdbcDriver";
    public static final String DEFAULT_URL      = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=e:\\Project\\Database.mdb";
    public static final String DEFAULT_USERNAME = "admin";
    public static final String DEFAULT_PASSWORD = "";
    /** Database connection */
    private Connection connection;
     * Driver for the DataConnection
     * @param command line arguments
     * <ol start='0'>
     * <li>SQL query string</li>
     * <li>JDBC driver class</li>
     * <li>database URL</li>
     * <li>username</li>
     * <li>password</li>
     * </ol>
    public static void main(String [] args)
        DataConnection db = null;
        try
            if (args.length > 0)
                String sql      = args[0];
                String driver   = ((args.length > 1) ? args[1] : DEFAULT_DRIVER);
                String url      = ((args.length > 2) ? args[2] : DEFAULT_URL);
                String username = ((args.length > 3) ? args[3] : DEFAULT_USERNAME);
                String password = ((args.length > 4) ? args[4] : DEFAULT_PASSWORD);
                db = new DataConnection(driver, url, username, password);
                List result = db.query(sql);
                System.out.println(result);
            else
                System.out.println("Usage: db.DataConnection <sql> <driver> <url> <username> <password>");
        catch (SQLException e)
            System.err.println("SQL error: " + e.getErrorCode());
            System.err.println("SQL state: " + e.getSQLState());
            e.printStackTrace(System.err);
        catch (Exception e)
            e.printStackTrace(System.err);
        finally
            if (db != null)
                db.close();
            db = null;
     * Create a DataConnection
     * @throws SQLException if the database connection fails
     * @throws ClassNotFoundException if the driver class can't be loaded
    public DataConnection() throws SQLException,ClassNotFoundException
        this(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
     * Create a DataConnection
     * @throws SQLException if the database connection fails
     * @throws ClassNotFoundException if the driver class can't be loaded
    public DataConnection(final String driver,
                          final String url,
                          final String username,
                          final String password)
        throws SQLException,ClassNotFoundException
        Class.forName(driver);
        this.connection = DriverManager.getConnection(url, username, password);
     * Clean up the connection
    public void close()
        try
            this.connection.close();
        catch (Exception e)
            ; // do nothing; you've done your best
     * Execute an SQL query
     * @param SQL query to execute
     * @returns list of row values
     * @throws SQLException if the query fails
    public List query(final String sql) throws SQLException
        Statement statement     = this.connection.createStatement();
        ResultSet rs            = statement.executeQuery(sql);
        ResultSetMetaData meta  = rs.getMetaData();
        int numColumns          = meta.getColumnCount();
        List rows               = new ArrayList();
        while (rs.next())
            Map thisRow = new LinkedHashMap();
            for (int i = 1; i <= numColumns; ++i)
                String columnName   = meta.getColumnName(i);
                Object value        = rs.getObject(columnName);
                thisRow.put(columnName, value);
            rows.add(thisRow);
        rs.close();
        statement.close();
        return rows;
}Solve one problem at a time. Get the database going, then worry about how you'll present it to the users. - MOD

Similar Messages

  • Please help me get started with my new ipad

    Hi all--merry Christmas!
    So, I'm away from home and just got my new ipad! Of course I want to play with it, but am not sure how to start. My full itunes library is on my iMac at home (and this is what I use when I sync my iphone). I do have my MacBookPro with me, but I don't use the itunes program on it very much. It looks like I need to connect my new ipad to my itunes in order to start using it....what will happen if I connect it to my laptop here, just to get going, and then later when I home I connect it to my iMac where my "real" itunes and all my apps are?
    Thanks for any info...I'm salivating to use it!!!

    Congrats you will love it!
    I don't see a problem with activating your iPad on your MBP. When you get home sync with iMac and set your iPad up as you like.
    Have fun!

  • Just updated all apple products how can I get back to the page on apple tv that helps me get started with mirroring

    Need to get back to home screen on apple tv to help get started with mirroring

    Ditto.
    You need to look for your itunes library under Computers and select it, then music.
    Music column is for web based content not local content, just to confuse everyone.
    AC

  • Please help me get started... JSP

    Hey, I'm brand new to web development. But I'd like to get into the field. For various reasons, I would like to start with JSP dev. I'm a C++ programmer, so concepts of OOP are not foreign to me. However, I don't have any idea as to where to start.
    I have installed Forte 4.0 software, Apache-Tomcat software, Sun JDK1.3, and JRun 3.0. Now I'm stuck. Although I have set the CLASSPATH, JAVA_HOME, and TOMCAT_HOME roots, I cannot write, compile, debug, or execute JavaServer Pages.
    Thank you for your time in assisting me.
    Moshe

    Hi,
    For debugging
    =============
    It seems that JSP runtime errors are impossible to debug. The exception
    thrown is always in some compiled servlet code. For example
    java.sql.SQLException, java.lang.ArrayIndexOutOfBoundsException,
    java.lang.NullPointerException and java.lang.ClassCastException. Is it
    possible to debug runtime errors, other than printing multiple checkpoint
    statements, which is not an efficient method?
    SOLUTION:
    There are no hard and fast rules to do that. It is very dependent on
    your JSP engine. In general, you need to find where your .java files
    are. You need to tell your JSP engine to leave them around. By default
    most engines delete them after creating the .class file. It may get
    tricky, though. Some engines put your HTML text into some kind of data
    structure (an object dump, basically) so it is not stored in your .class
    file. This makes your class files much smaller, and the HTML is not
    stored on the VM's stack. This makes it very difficult to debug.
    One suggestion is to use Forte for Java to do debugging of JSP codes. It can be
    downloaded and purchased from http://www.sun.com/forte. The following is
    a short tutorial to demonstrate how to debug a JSP file, set breakpoints,
    and watch variable content values during runtime.
    1) Set the compiler property for your JSP.
    - Go to the Explorer window.
    - Select your JSP file.
    - Set the Servlet Compiler property to Internal Compilation.
    (Hint: Use the context-sensitive Properties window.)
    - Set the Debugger property to Servlet/JSPDebugging.
    2) Now you will debug the JSP file by setting breakpoints, watching
    variables, and switching between the JSP and corresponding servlet.
    Set the breakpoint in your JSP file.
    - Go to the Source Editor window.
    - Select a few lines to watch
    - Using the context-sensitive menu (right click), select Add/Remove
    Breakpoint. This line will turn red to indicate that there is a
    breakpoint for this line.
    3) View the breakpoints in the corresponding servlet for your JSP file.
    - Go the Explorer window.
    - Select your JSP file.
    - Using the context-sensitive menu, select View Servlet.
    You will see the corresponding servlet in the Source Editor window.
    At the bottom of the Sourde Editor window, you should see two tabs,
    one for JSP and another for the corresponding servlet.
    - Select the servlet's tab.
    - Using the context-sensitive menu, select Clone view.
    You should see a separate window with the servlet code and
    breakpoints. These breakpoints automatically came from the JSP
    file.
    - Place the JSP file and corresponding servlet window side by side so
    that you can simaltaneously view the execution of JSP as well as
    the servlet.
    4) Select some variables to watch during the execution.
    - Go the window containing the servlet's source code.
    - Using the context-sensitive menu, select Add Watch.
    - In the resulting dialog box, enter a variable name for the Watch
    Name.
    - Click on the OK button.
    - To view the watch variables, go to the Main menu and select View ->
    Debugger. At the bottom of the Debugger window you should see a
    tab named Watches.
    - Select the Watches tab.
    You should see the added variables.
    5) To start the debugging session, go the Main menu and select Debug ->
    Start Debugging.
    The execution will stop at the first breakpoint in the JSP file.
    If you see the servlet code, there are also execution will stop at
    the first breakpoint.
    - To continue the execution, go the JSP source code in the Source
    Editor window and press Control-F5 to restart the debugger.
    Execution will stop at the next breakpoint. In the servlet code,
    execution will also stop at the next breakpoint.
    - Go to the Debugger window and select the Watches tab to view the
    contents of the variables.
    6) If you set any breakpoints in the servlet code, those breakpoints
    will automatically appear in the JSP file.
    This way, you can set breakpoints in either JSP file or corresponding
    servlet.
    7) While executing the JSP, observe the contents of the variables in the
    Debugger window.
    8) Once execution has reached its end, close the debugger by going to
    the Main menu and selecting Debug -> Finish Debugging.
    For more tutorials and demo, please visit:
    http://www.sun.com/forte/ffj/demo/online_demo.html
    http://access1.sun.com/SRDs/srd_repository/F4JCE_SRD.ps
    For information and online support, please visit:
    http://forte.sun.com/cgi-bin/WebX
    http://www.sun.com/forte/ffj
    I hope this will help you.
    Thanks
    Bakrudeen

  • Help in getting started with java 3d

    Hi everyone,
    I am very new to java3d and I started learning it from few books and online tutorial.
    However, in my very first program that I trying to code, I get error when I try to import following:-
    import com.sun.j3d.utils.universe.SimpleUniverse;
    The compilation error that I am getting is that "com.sun.j3d cannot be resolved". I have already installed java 3d. I can see java3d package in the Program Files/java directory.
    Any suggestions would be greatly appreciated.
    Thanks!

    On the instalation you have to use the default location, or the location where your SDK is installed.
    Also, check if the CLASSPATH is defined correctly in your Environment Variables for JAVA_HOME and PATH.
    You can also try to define the Java 3D jar files in you classpath before you try to run your file. Or can also try to use an IDE like NetBeans or Eclipse, it will help you a lot with your import declarations.

  • Need help on getting started with shopping cart!!

    hi guys,
    i want to build a fairly simple shopping cart with servlets and jsps.. can you please point me to a starting point.. a tutorial or a general road map for it.. i am pretty okay with servlets and jsps and currently using them for a web-app..
    any help would be greatly appreciated..thanks..

    go to http://www.moreservlets.com, download the free pdf book "Core Servlets and Java Server Pages", there is a example program on section 9.4 talks about shopping cart.
    Hope it helps.

  • Need help to get started with iMovie

    I have used the iMac for sometime but never created a movie. With my new iMac, I want to start using the iMovie '09. The first basic problem is that it will not accept any of my videos.
    I have videos made on a fairly new Cannon camera (*.movl), on a Flip recorder (*.avi). I thought the program would accept the *.mov but it will not. I have converted these videos to mpeg4, mp4, mov using ffmpegx, and mpeg streamclip, but they still will not be accepted by the iMovie program. I tried to drag and drop the videos without success, both with and without first creating a "New Project". What am I doing wrong?
    Thanks

    Hi
    This is a very complexed question (I think) and I can only suggest partial help if any.
    I would from still photo Camera import to iPhoto. Mine does this and so the movie
    sequences too.
    Then after closing iPhoto and opening iMovie - I see in Browser/Events window high
    at left hand - My Mac hard disk and under this iPhoto Library
    And here I find my movie sequences from my Leica D-Lux and vife Nikon D300s
    Yours Bengt W

  • Help on getting started with Spring MVC, WebFlow; Where can it be applied ?

    I'm an individual programmer, developer and I see a huge demand (at the corporate level) for the frameworks: Spring, Spring MVC, webflow, and Hibernate. Popular today: Spring MVC, webflow, GWT.
    I've been going through the tutorials, and the technology looks awesome ! What I would like to know, is.. It's used in corporate sites, why not for smaller sites. How can I apply these frameworks in building websites ?
    I can't imaging doing any kind of serious website building without a modern CMS or Portal framework (whether in Java/php-opensource), And yes, MVC gives you the validation and authentication hooks to be used.
    The spring framework, with it's extensive scope, is a bit overwhelming, and implies that there could be a significant amount of architecture, design and planning time needed before starting implementation on a project
    All the demo's on Spring, cover some elementary, contrived example.
    If I learn these technologies (and I'm well on my way), how do I put them into practice, and in what context (no pun intented) do I use them ? I don't want to rebuild a CMS system, but I'd like to employ these frameworks effectively.

    user1944443 wrote:
    The spring framework, with it's extensive scope, is a bit overwhelming, and implies that there could be a significant amount of architecture, design and planning time needed before starting implementation on a projectYes, usually there is. Unless you're using the frameworks to build a home page for your kittens. Then you usually don't need to put that much effort into it.
    All the demo's on Spring, cover some elementary, contrived example.I'm sure you realize that they have to. There's no "follow these examples and you'll become a competent programmer" method of learning invented yet and frameworks usually need to document the basic cases extensively.
    If I learn these technologies (and I'm well on my way), how do I put them into practice, and in what context (no pun intented) do I use them ? I don't want to rebuild a CMS system, but I'd like to employ these frameworks effectively.You'll just need to come up with a project you'll be interested in finishing or at least developing for a while.
    I'm not sure whether I managed to answer your question or not, but if anything was left unclear, just ask.

  • FAQ: How do I get started with Photoshop Elements Editor, or What do all these tools do?

    Opening an image editing application for the first time can be intimidating. The more powerful the tool, the more complicated it can be to learn to use. Below are a list of resources to help you get started with the Photoshop Elements Editor.
    I just bought Photoshop Elements, where do I start?
    There are a lot of directions you can go when you first make your purchase. Here is your first roadmap.
    Getting Started Tutorials
    What do all these terms mean?
    There are some common words tossed around when talking about image editing or tool use. Here is a helpful guide to define these: Photoshop Elements key concepts
    Photoshop Element Help Topics:
    Workspace basics
    Tools
    Color and tonal correction basics
    Elements Basics, an overview of Elements' essential concepts on Photoshop Elements User.com
    Where can I find some tutorials on the web?
    There are many resources for learning Photoshop Elements on the internet. Here are some that we recommend.
    Photoshop Elements: Where can I find some good basic tutorials? on the Photoshop Feedback site.
    Like Photoshop Elements on Facebook for daily tutorials and inspiration. As well as the occasional contest.
    Editing Tutorials for Photoshop Elements on Photoshop.com
    Getting Started with the Elements Editor on Photoshop Elements User.com
    Photoshop Elements for Dummies.com
    What about video tutorials?
    Some find it easier to watch a product being demonstrated and explained by an expert
    Learn Photoshop Elements 11 on Adobe TV
    Photoshop Elements channel on YouTube
    Where can I find books about learning Photoshop Elements?
    Photoshop Elements books on Pearson Peachpit Press

    Hi Christoph and WarriorAnt,
    Thank you both for the replies.
    I don't know anything about GarageBand because I've never used it. I've never used any music software before, (other than iTunes, Ha!)
    I don't have GarageBand on my Mac because it wasn't stock on the old Powerbook G4, so I would have to buy it. I'm happy to do that if I can figure out that it does what I want ... but I'm overwhelmed by the info at Apple's site. Too much for a beginner like me. Even the wikipedia.com entry for GB uses too many terms I don't know, so I'm easily lost.
    I just want to be able to set up drum loops and play along with them. The main thing is that I'm able to use third party loops. There are so many really amazing loop products out there ... jungle drums, acoustic jazz drums, lounge, etc. I don't want to get caught up in anything proprietary (like Band-In-A-Box) because the selection is limited. I'm sure GarageBands loops are great, but I want access to all these other third party loops as well ... loops that were not specifically made for GarageBand.
    Will GarageBand let me drop in any and all drum loops from these other companies?
    And does GarageBand work like a basic sequencer, where I can program up an intro, X number of measures of a loop, then a turnaround, then a variation loop, then an ending, etc?
    I know the high-end stuff like Native Instruments Kontakt does this, but unfortunately it also does a kazillion other professional-level things I will never need and don't want to pay for (and which make the software more complex and daunting).
    Thank you again, both of you, for responding and helping me with this project.
    Just a little more advice on those two questions would really go a long way.
    -JOHN

  • Getting Started with 9iAS Wireless

    I installed the 3 CDs for 9iAS and when I look at my inventory for installed Oracle products I see that 9iAS wireless is installed, however I can't find any documentation, links or admin programs that help me get started with it. I have a WAP emulator and I want to write applications in PLSQL in the XML format, however it rejects them claiming that the page is HTML and not accepted. What do I need to do to write applications in PLSQL that will work on a WAP enabled device.
    Thanks

    You can find documentation to Oracle9iAS Wireless Release 2: http://otn.oracle.com/docs/products/ias/doc_library/90200doc_otn/wireless.htm
    In the Getting Started and System Guide, you can find a walkthough of the product: http://otn.oracle.com/docs/products/ias/doc_library/90200doc_otn/wireless.902/a90486/pags.htm#1005603
    Additionally, here is a link to a hosted version of Oracle9iAS Wireless called the Mobile Studio: http://studio.oraclemobile.com. This has infrastructure set up so you can easily access your application through voice, SMS, any mobile browser...
    Hope this helps,
    Kalle
    [email protected]

  • How to get started with SNMP.. please help me

    I am completely new in SNMP but I really really want to learn it so please help me :)
    I have tried to type snmpget and snmpwalk  in the prompt with some proper device �and OID information and I get some information back (do not really understand the return massages though).
    But I would like to make a manager program in java that calls some network-clients and report the return messages. I would like to use snmp4j (is this a good choice?).
    If somebody have some piece of simple code that sets up a manager- client snmp program, I would be so happy to see it.
    Thanks a lot in advance.
    (If anyone knows some good tutorials or anything that can help me get started I will also appreciate this)

    try using Delete Messages Once Read or write ur own module for achieving the same or use SAP Connect for acheiving the same..if ur intention is to just read mails..!

  • What do you recommend to get started with Dynamics Marketing? Book, You Tube, help searches, etc.? Please advise.

    Trying to get started with marketing using dynamics and tutorials, help searches and you tube seem to be fruitless. What do you recommend to get started? Buy a book to walk thru setting up company settings and creating campaigns? Need some easy steps on
    not what the software is capable of but how to do it with easy 1-2-3 steps.  Please share you thoughts!!

    Hi cb,
    I would recommend a few articles here. There are videos, walkthroughs and ebooks that you can take a look at the have
    a better understanding of not only what the product is capable of, but how to actually configure and work with it.
    Help & Training - Videos and ebooks
    TN Articles 

  • Help Needed with getting Started With Office 365 Development C# Rest API

    We have a O365 Tenant Setup with a Federated Active Directory Setip we want to be able to right code that will connect to our tenant and perform basic CRUD operations against it (ex. Creating mail boxes)
    The problem is we want this to be contained in a CLR trigger In SQL so say if a new user is added to our user table then we would create a new AD account for that user and also create a mailbox.
    But I cannot find and example on how to connect to Office 365 using the REST API (Not the SDK because you can not add the connected service to a class library) and before the required actions that we need to do. All the example I have found are with the
    SDK API and/or require window 8 and that is also not an option.
    Please help I do not know where to start, and I would love to see some examples done in c# and not using the SDK.
    Thanks,
    Andrew Day

    Hi,
    >> Instead of SharePoint URLs I would use the O365 API URL?
    Yes, in my sample code, I was accessing the File resource by using the O365 File API. In your case, you need to acquire the token to access the Mail resource and use O365 Mail API.
    By the way, I think the article
    Understand Office 365 app authentication concepts will help you to understand the authentication process in Office 365 Development.
    >> Why can I not use the SDK API with a class Library?
    Actually, you are able to reference the Office 365 .NET SDK in the class Library. But the class library project type was not supported by Visual Studio Office 365 Development Tool. As a workaround,
    you can reference the SDK manually in your project.
    Since your original question is about “getting started with Office 365 Development C# Rest API”, if you have more questions about the Office 365 SDK, I will suggest you posting a new thread
    to discuss the Office 365 SDK. It will involve more other community members to share their ideas and experience on a specific a question and for others who had a similar question could also find the valuable information quickly.
    Regards,
    Jeffrey
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • When attempting to start iTunes, I get the following: "The iTunes library file cannot be saved. An unknown error occurred (-50)." Can someone please help me get this fixed?

    When attempting to start iTunes, I get the following: "The iTunes library file cannot be saved. An unknown error occurred (-50)." Can someone please help me get this fixed?

    Same problem here since latest update.  As usual poor support from Apple with no answer or fix for this bug.

  • Sorry I do not understand I neeed to get started with elements 10 and so far no help received

    I am trying to get started with Adobe elements 10 and selected organise so as to transfer my many files over
    this I have been unable to do.
    Being asked for ID name ( already registered) which mena scoming out of one page hunting in fact its all very frustrating.. HELP
    Post message sorry how do I get help?????????

        Hi casheasy!
    I sure don't want our first month with you to start off on the wrong foot! I'd be happy to review the charges on your first bill and make sure all is correct. I have followed you in the forums. Please accept my request and follow me back. Then, please send me a DM with your name and mobile number and I'll check it out for you!
    ChristinaB_VZW
    VZW Support
    Follow us on Twitter @VZWSupport

Maybe you are looking for

  • Columns & Text Flow Query

    My document set-up is two columns. I want to insert images with captions in the left column and text-only in the right column. I would like to have right column text contain itself within the right column. Ditto for the left column. I do not want con

  • Facebook open graph & Business Catalyst

    Hi all This is perhaps leaning toward a FB integration problem rather than BC. But hey - it might help I have created a FB app called Skimax Deals (although its not reall an app) I have loaded the data into the Skimax Social part which enables me to

  • Setting Preview Image for iMovie

    I just created several tutorial videos using iMovie. The videos are embedded in an online course I'm developing. Does anyone know how to set the preview image that appears for the video? Right now, the preview image (i.e. the image that appeard under

  • Genius won't connect - Your request is temporarily unable to be processed. Please try again later.

    Have been getting same error for over a month now...whilst trying to turn on Genius in upgraded version of iTunes. Your request is temporarily unable to be processed. Please try again later. Contacted Apple support and followed a few discussions with

  • Keyhole DRM

    I've just started getting the following error: "Shockwave.com Keyhole DRM Application has encountered a problem and needs to close. We are sorry for the inconvenience." I see that others have previously had the same error. Contacting support has prov