private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:        MyConnection mc = new MyConnection();
        String username = jTextField1.getText().trim();
        String userpass=new String(this.jPasswordField1.getPassword());
       try{
        if(username.equals("")||userpass.equals("")){
            message.setText("用户名和密码不能为空!!!");        }
         Connection conn = null;
         PreparedStatement pstatm = null;
         CallableStatement cstatm = null;
         //ResultSet rs  = null;
         
             conn = mc.getConnection();
            cstatm = conn.prepareCall("{call user_id_name(?,?)}");           cstatm.setString(1,username);
           cstatm.setString(2,userpass);
           
           cstatm.registerOutParameter(2, Types.VARCHAR); //注册
 
             int flag = pstatm.executeUpdate();
              if(flag!=0){
                System.out.println("成功");
                 
              }         }catch(SQLException e){
          e.printStackTrace();         }
    }      
      我建了个存储过程 就是set 不进去值 实在找不出错误了 那位高手 帮忙指点哈 谢谢了                                  

解决方案 »

  1.   

    不晓得问题,但觉得这句代码是有问题的 
    String username = jTextField1.getText().trim();
    String username = jTextField1.getText();
    if (username!=null){
     username = username.trim();
    }
      

  2.   

    改一哈
     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:        MyConnection mc = new MyConnection();
            String username = jTextField1.getText();
            if(username!=null){
              username = username.trim();
            }
            String userpass=new String(this.jPasswordField1.getPassword());
           try{
            if(username.equals("")||userpass.equals("")){
                message.setText("用户名和密码不能为空!!!");        }
             Connection conn = null;
             PreparedStatement pstatm = null;
             CallableStatement cstatm = null;
             //ResultSet rs  = null;
             
                 conn = mc.getConnection();
                cstatm = conn.prepareCall("{call user_id_name(?,?)}");           cstatm.setString(1,username);
               cstatm.setString(2,userpass);
               
               cstatm.registerOutParameter(2, Types.VARCHAR); //注册
     
                 int flag = pstatm.executeUpdate();
                  if(flag!=0){
                    System.out.println("成功");              }
                 if(cstatm.getString(2).equals("128080")){
                   message.setText("登录成功");             }else{
                   message.setText("登录失败");             }         }catch(SQLException e){
              e.printStackTrace();         }
        }                                            private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            System.exit(0);
        }                                            /**
        * @param args the command line arguments
        */
         public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Userframe().setVisible(true);
                }
            });
        }
    楼上回答的问题 应该不是 我觉的 那是等效的
      

  3.   

    username空指针啊判空时用null和“”是不一样的。先初始化username,再获取、操作
      

  4.   

    没看到你加载驱动的部分呀,应该是先加截驱动,再创建Connection 和预备语句等等。