Database connectivity error-login time expired

everytime i try to connect it displays the error- login time expired..moreover if connected once, then while entering values if i press insert button, null pointer exception is thrown.. kindly help me in resolving the error..
package database1;


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


public class ctest extends javax.swing.JFrame {

    /**
    * Creates new form ctest
    */
    public ctest() {
        initComponents();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:emp1","sa", "dewansh");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ctest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ctest.class.getName()).log(Level.SEVERE, null, ex);
        }
           
        JOptionPane.showMessageDialog(rootPane, "connected");
    }

    /**
    * 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.
    */
    @SuppressWarnings("unchecked")
    //                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setText("database connection test");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(148, 41, -1, -1));

        jButton2.setText("insert");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 210, -1, -1));

        jLabel1.setText("empid");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 90, -1, -1));

        jLabel2.setText("empname");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 120, -1, -1));

        jLabel3.setText("empsalary");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 150, -1, -1));
        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 90, 70, -1));
        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 120, 70, -1));
        getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 150, 70, -1));

        pack();
    }//                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:emp1","sa", "dewansh");
        JOptionPane.showMessageDialog(rootPane, "connected");
        }
       
            catch (ClassNotFoundException ex) {
                Logger.getLogger(connection_test1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
          Logger.getLogger(ctest.class.getName()).log(Level.SEVERE, null, ex);
        }
        // TODO add your handling code here:
    }                                       
Connection con;
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        try {
            int empid=Integer.parseInt(jTextField1.getText());
            String empname=jTextField2.getText();
            int empsalary=Integer.parseInt(jTextField3.getText());
          // String sql_string="insert into empinfo(empid,empname,empsalary ) values(101,'xyz',40000)";
            String sql_string="insert into  empinfo(empid,empname,empsalary) values("+empid+",'"+empname+"',"+empsalary+")";
            Statement my_statement= con.createStatement(empsalary, empsalary);
         
            int no= my_statement.executeUpdate(sql_string);
            JOptionPane.showMessageDialog(rootPane,"saved"+no);
        jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
        } catch (SQLException ex) {
            Logger.getLogger(ctest.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane,ex.toString());
        }
         
         
        // TODO add your handling code here:
    }                                       

    /**
    * @[USER=14158]param[/USER] args the command line arguments
    */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
        * For details see https://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ctest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ctest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ctest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ctest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ctest().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                   
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration                 

}
error:-

run:
Aug 25, 2013 7:24:48 PM database1.ctest 
SEVERE: null
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Login timeout expired
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at database1.ctest.(ctest.java:26)
    at database1.ctest$3.run(ctest.java:157)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at database1.ctest.jButton2ActionPerformed(ctest.java:111)
    at database1.ctest.access$100(ctest.java:17)
    at database1.ctest$2.actionPerformed(ctest.java:68)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Replies

  • Rits rishi
    Rits rishi
    please reply.. i urgently need the solution..i am unable to do work.. my connectivity does not work after 7 pm..i don't know why.. even the dsn connection does not setup because of the sql driver incompatibility..😔 will i never be able to setup dsn connection after 7 pm with sql server authentication??😖
  • sookie
    sookie
    In program, driver details are not correct. You are using SQL Driver but passing the URL for JDBC - ODBC. Please check the connection details. Try replacing the driver as "sun.jdbc.odbc.JdbcOdbcDriver" instead of "com.microsoft.sqlserver.jdbc.SQLServerDriver"
  • Rits rishi
    Rits rishi
    sookie
    In program, driver details are not correct. You are using SQL Driver but passing the URL for JDBC - ODBC. Please check the connection details. Try replacing the driver as "sun.jdbc.odbc.JdbcOdbcDriver" instead of "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    but "sun.jdbc.odbc.JdbcOdbcDriver" is for 32-bit pc & my friends who are using the same statement:- "sun.jdbc.odbc.JdbcOdbcDriver" on 64-bit pc are too facing the same problem..is there any other solution??

You are reading an archived discussion.

Related Posts

right now,Im learning php .I want to do a project on php ,so can any one suggest that which type of project should i do
In a Metal scrap recycling Industry, is there a method which is more efficient than a manual hand sorting process for sorting a scrap into different metals?
I have seen in wiki susceptance is the imaginary of admittance. but its not a clear definition for suscep. The reactance is the opposition of change of voltage and current...
plz tell me the circuit which has to be implemented ....
Hi friends am a student of University of Adelaide, Australia. I need one innovative non technical seminar topic like Solar powered Catamaran, Automatic Car parking System. Please give me your...