Opening dbs thru button events, help, i`m a newbie..

i have the following fn for opening the db
public static void main(String args[]) throws Exception
new login(new javax.swing.JFrame(), true).show();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
open();
select();
static void open() throws SQLException
// ODBC data source name
String dsn = "jdbc:odbc:dslogin";
String user = "";
String password = "";
// Connect to the database
con = DriverManager.getConnection(dsn, user, password);
// Shut off autocommit
con.setAutoCommit(false);
static void select() throws SQLException
Statement stmt; // SQL statement object
String query; // SQL select string
ResultSet rs; // SQL query results
boolean more; // "more rows found" switch
query = "select user,password from dblogin";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
// Check to see if any rows were read
more = rs.next();
if (!more) {
System.out.println("No rows found.");
return;
// Loop through the rows retrieved from the query
while (more)
// System.out.println("kkkk");
System.out.println("umm" + rs.getString("user"));
System.out.println("ummmm" + rs.getString("password"));
more = rs.next();
rs.close();
stmt.close();
now my problem is this..while the above open and select fns work fine in void main, i`m trying to open the db upon clicking a button..heres what i tried to do :
cmdsubmit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdsubmitActionPerformed(evt);
private void cmdsubmitActionPerformed(java.awt.event.ActionEvent evt) {
open();
seelct();
when i try it i get the error message exceptions must be caught or throw or sumthing like that and i`m new to java so i`ve no idea how to go about doing it..help please..

On JDBC:
You only need to register a driver with the DriverManager once, and this is done (by JDBC conform drivers) when the driverclass is loaded. You may want to do this in a static initializer:
import java.sql.*;
class MyClass{
    static {
        try {
            // load driver class, which automatically registers itself
            Class.forName("sun.jdbc....");
        } catch(Exception ex) { /* handle it, throw error */ }
    // later
    Connection con = DriverManager.getConnection(...);
}Even better is NOT to hard-code the driver at all. Use
java -Djdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver;oracle.jdbc.OracleDriver MyClassinstead.
Fritz

Similar Messages

  • Button Event Help

    Hi, I have created a Frame that the user can draw in. It is a separate class that I call in my main program from a different file. I have a button on my frame that I want to run a method to save the graphical contents of the frame as a type Image. This works fine, and I have created the image. Now I need to return the image to my main program somehow. I want it only to return to my main when the button is pressed. The actionPerformed cannot contain a return statement, and I cannot call a getImage (from the frame) in my main anyway, because I want it to be initiated by the button push, which is located in the Frame file and not in the main. Can anyone help me? I will post the code. Ignore the Picture and InterruptedException in my actionPerformed class, they just convert the image in other classes, but they're not important. An explanation to return the image would be perfect.
    Here is my main:
    class LoadPictures
        public static void main (String [] args) throws IOException, InterruptedException, AWTException
            PaintArea pa = new PaintArea ();
            pa.loadArea (pa);
    Picture pic= pa.getPic() //<---false method. This is what I want to happen when you click the button in the frame.
        }}Here is my frame, entitled PaintArea:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class PaintArea extends Frame
        static int x, y;
        static Graphics g;
        PaintArea ()
            addWindowListener (new WindowAdapter ()
                public void windowClosing (WindowEvent e)
                    hide ();
            setSize (400, 400);
            setVisible (true);
            g = getGraphics ();
        public void loadArea (PaintArea pa)
            Button button = new Button ("Save");
            // pa.add (button);
            button.setSize (2, 2);
            pa.show ();
            final PaintArea pa2 = pa;
            button.addActionListener (new ActionListener ()
                public void actionPerformed (ActionEvent ae)
                    try
                        Image image = pa2.saveScreen (pa2);
                        //Picture pic = new Picture (pa2);
                    catch (AWTException e)
                        System.err.println (e);
                        System.exit (1);
                    // catch (InterruptedException ie)
                    //     System.err.println (ie);
                    //     System.exit (1);
            pa.addMouseListener (new MouseAdapter ()
                public void mousePressed (MouseEvent me)
                    x = me.getX ();
                    y = me.getY ();
                    g.fillOval (x - 5, y - 5, 10, 10);
            pa.addMouseMotionListener (new MouseMotionAdapter ()
                public void mouseDragged (MouseEvent me)
                    x = me.getX ();
                    y = me.getY ();
                    g.fillOval (x - 5, y - 5, 10, 10);
        public Image saveScreen (PaintArea pa) throws AWTException
            Image image = createImage (new Robot ().createScreenCapture (pa.getBounds ()).getSource ());
            return image;
    }Thank you very much, everyone!!

    When you open the frame, use wait() to suspend action in the main program. When the button is pressed, call notify() on the same object. Then the focus is back in the main program's code.

  • I'm trying to sync my iphone in IPhoto. I get this message "our MobileMe account information is not correct. The provided login or password is not valid." when I click on the "Open MobileMe Preferences" button, it doesn't take me there.  Help please.

    I'm trying to sync my iphone in IPhoto. I get this message "your MobileMe account information is not correct". "The provided login or password is not valid." when I click on the "Open MobileMe Preferences" button, it doesn't take me there.  Help please.

    Mobile me has been discontinued for over a year.  What system  and iPhoto versions are you running?
    How are you trying to sync?  With Photo Stream or thru iTunes?
    Do you have an iCloud preference pane in your System preferences?
    Do you meet the minimum requirements for iCloud and Photo Stream?
    iCloud: System requirements
    iCloud: Photo Stream FAQ
    OT

  • How can a new button Event open sales order

    CRM WEB UI issue.
    On assignment Block there is a New button , on New button Event i have to open sales order .
    Please help me.
    Thanks in advance .
    Kumar6

    Hi Kumar,
    Whenever you got any requirement then find out on Web UI how they have done it. As now you want to show sales order then first find out Component name for Sales order.
    So Go to transaction u2018CRM_UIu2019. Chose u2018SalesProu2019 as a Role.  In Navigation Bar click on u2018Sales Cycleu2019  and in Second level link there is u2018Sales Orderu2019. Click on it. Check  it is a screen you want on your button click.
    If yes then you need to find its Technical Data (details). So click inside Work Area and press u2018F2u2019 key.
    Then you will get UI component name, View name , Context name, Role key, etc. So you have to pick that UI Component name and give it in Transaction Code  u2018CMP_WD_BSPWBu2019.
    Now Go To  u2018Run Time Repositoryu2019 , In Component Interface They have created u2018Component Interfaceu2019 that you need to call in your Button click event. If you donu2019t know use of u2018Component Interfaceu2019 then first read it else its good for you.
    Well next time when you will write any Question, In Subject write it in One line so that all can see in list and answer you quickly.
    Thanks,
    Durgesh Pagar.

  • HT201407 My iphone suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can open the iphone itself. please help me.

    My iphone suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can open the iphone itself. please help me.

    My iphone 5 suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can't open the iphone itself. please help me.

  • I closed all my toolbars, now cannot find how to open again , not even a 'help' button.

    I closed all my toolbars. Now cannot find out how to open them, not even a help button
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB6.5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)

    In Firefox 3.6 on Windows you can hide the menu bar via "View > Toolbars" or via the right click context menu on a toolbar.
    Press and hold the Alt key down to bring up the menu bar.
    Go to "View > Toolbars" or right-click the menu bar or press Alt+V T to select which toolbars to show or hide.
    See also [[Menu bar is missing]]

  • I'm getting a similar message: There was an error opening the database..." and the only option I get is a "quit" button. Help!

    I'm getting a similar message: First it offers me chance to repair - but if I it repair, it crashes.  Then if I select do not repair I get the following warning: There was an error opening the database..." and the only option I get is a "quit" button. Help!

    From the path in the error message you posted it appears that the library is not on your internal (root) drive.
    What type of disk is the library on and how is it formatted?
    The crash log Léonie is referring to is what is printed out when Aperture crashes. You wrote that Aperture crashes in your first post so if the app crashes you must have gotten a crash report.
    Message was edited by: Frank Caggiano

  • When I start my mac book pro the screen flashes on and off and then a blue color before it open to the log in screen. Sometime a program will shot down buy it's self without me clicking the quit button. Help?!

    When I start my mac book pro the screen flashes on and off and then a blue color before it open to the log in screen. Sometime a program will shot down buy it's self without me clicking the quit button. Help?!

    If you keep getting a 'red' message it means that the HDD is faulty and will have to be replaced.  You will have to format the new HDD in Disk Utility>Erase and then install the OSX and your data from Time Machine.
    Ciao.

  • Hi, can anyone help? My ipad 3 wont open, the slide button is stuck.

    Hi, please can anyone help? My apad 3 won't open, the sliding button isn't working, its stuck. I,ve tried shutting shutting it down but its just not working.

    Try a reset:
    Hold the Sleep and Home button down until you see the Apple logo.

  • TS4079 I hold down the home button with Siri enabled on my Iphone 4 but it will not open, internet is present.. help??

    I hold down the home button with Siri enabled on my Iphone 4 but it will not open, internet is present.. help??

    Make sure Siri isn't disabled in Settings > General > Restrictions.
    If that isn't it, did you try to restore as a new device?

  • I Just updated the software of my iphone 4s thru phone, now the photo application won't open... Please help me what to do?

    Hi! I'm Ralph.. Just updated my iphone 4s from 6.1.2- 6.1.3. ... Now the photo application won't open... Please help me what to do

    Why would this be covered under warranty?  There is nothing wrong with the device, it simply needs to be restored.
    As already stated twice in this thread, disable ALL security software on the computer and restore the device.

  • How to Capture Button event on TrainBean navigation

    Hi All
    i m being required to capture a button event in train bean Navigation, i m doing customization in Iexpense Module,here in Create IExpenseReport i need to capture the events of Remove,Return etc.how is it possible any clue would be very helpful.
    Thanx
    Pratap

    try this..
    if (GOTO_PARAM.equals(pageContext.getParameter(EVENT_PARAM))
    "NavBar".equals(pageContext.getParameter(SOURCE_PARAM))
    // This condition checks whether the event is raised from Navigation bar
    // and Next or Back button in navigation bar is invoked.
    int target = Integer.parseInt(pageContext.getParameter(VALUE_PARAM));
    // We use the parameter "value" to tell use the number of
    // the page the user wants to visit.
    String targetPage;
    switch(target)
    case 1: targetPage = "/oracle/apps/dem/employee/webui/EmpDescPG"; break;
    case 2: targetPage = "/oracle/apps/dem/employee/webui/EmpAssignPG"; break;
    case 3: targetPage = "/oracle/apps/dem/employee/webui/EmpReviewPG"; break;
    default: throw new OAException("ICX", "FWK_TBX_T_EMP_FLOW_ERROR");
    HashMap pageParams = new HashMap(2);
    pageParams.put("empStep", new Integer(target));
    pageContext.setForwardURL("OA.jsp?page=" + targetPage,
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    pageParams,
    true, // Retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO, // Do not display breadcrumbs
    OAWebBeanConstants.IGNORE_MESSAGES);
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Not able to capture button event in extended controller

    Hi Gurus,
    I am not able to capture the button event (of seeded controller) in extended controller.
    I have written code in extended controller like below:
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean){
        String str = pageContext.getParameter("event"); // copied from seeded controller for the button event //
          if ("editLines".equals(str)) {
            //cutom validation
      super.processFormRequest(pageContext, webBean);
    Please help me in resolving the issue.
    Thanks,
    Srinivas
        ///my cutom validateion

    Hi Bm,
    Thanks for your response.
    I have tried the same but no luck.
    Please help in getting this resolved.
    Thanks,
    Srinivas

  • How to get a form field valud in delete PL/SQL Button Event Handler

    Hi Friend,
    I have a form. when user clicks delete button. we want to remove system dodelete function
    and add a delete script
    Under delete-top category,
    how can I get value of form EVENT_NUMBER field in form at delete PL/SQL Button Event Handler?
    DELETE FROM PTEAPP.PTE_EVENTS WHERE eventnumber = EVENT_number
    But when I try to save this form and get message as
    1721/15 PLS-00201: identifier 'EVENT_NUMBER' must be declared
    Thanks for any help!
    newuser

    I did something similar but wasn't using a stored procedure. Couldn't you set a flag variable once you know you're not doing the insert and in the "before displaying the form" section put an IF to check if your flag was set, and if so do an HTP.Print('You are overpaid buddy!');
    Then just reset your flag.

  • Open/Close chart button not working in Account Fact Sheet

    Hi,
    My requirement is like this:
    There are some standard assignment blocks like Contacts and custom assignment blocks like Sales order details in  Account Fact Sheet(AFS). There is one Open/Close chart button present at the top of each assignment block. When it is clicked, a pictorial representation of data in AFS is displayed.
    My question is where is the code written for this functionality. The tool bar based buttons defined in the implementation class of corresponding component like get_buttons, get_system_buttons etc are not at all defined Also there is no coding written in the HTML page of the view.
    Please let me know if anybody worked on this.
    Regards,
    Narendra

    Hi All.
      We are working on SAP CRM 7.0 EHP2.We need to show account factsheet on Account Overview page in IC-Agent Role.
      We are using account factsheet BP_ACCOUNT_FS.In this account sheet,data is not populated or not able to select the org data in view " Sales Organization Selector".same data is appearing  in Account Overview page.
    Same type of issue (Account Shipping data, Account Sales data, Account Billing Data etc is not coming in factsheet)was posted eariler and status of post is resolved but solution is not given.
    Please help us in this issue.
    Regards,
    Urvashi

Maybe you are looking for