java executeupdate,为什么executeUpdate(sql)返回-1呢

package com.user;

import java.sql.Connection;

import java.sql.Statement;

import java.sql.DriverManager;

import java.sql.*;

public class userBean {

private String userId;

private String userName;

private String password;

private String email;

private int count;

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public void setUserName(String userName) {

this.userName = userName;

}

public void setUserId(String userId) {

this.userId = userId;

}

public void setPassword(String password) {

this.password = password;

}

public void setCount(int count) {

this.count = count;

}

public String getPassword() {

return password;

}

public String getUserId() {

return userId;

}

public String getUserName() {

return userName;

}

public int getCount() {

return count;

}

/**

* 获取连接

*/

private Connection conn = null;

private void getConnection() {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver&quot

9f7588d3b12cd5d674b5f81c0b8fc6cb.gif;

try {

conn = DriverManager.getConnection("jdbc

5b24fae4cde99750994428c024162093.gifdbc:ues&quot

9f7588d3b12cd5d674b5f81c0b8fc6cb.gif;

} catch (SQLException ex1) {

}

//            Statement stmt;

} catch (ClassNotFoundException ex) {

ex.printStackTrace();

}

}

/**

* 检查用户名是否可用的方法

* @return  用户的个数

*/

public void checkUserName() {

int i = 0;

this.getConnection();

String sql = "select count(*) from userreg where username='" +

this.userName + "'";

System.out.println(sql);

try {

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {

i = rs.getInt(1);

}

} catch (SQLException ex) {

ex.printStackTrace();

}

this.setCount(i);

System.out.println("检查用户名:" + count);

// return count;

}

/**

* 添加用户的方法

* @return  用户插入的行数

*/

public void addUser() {

this.getConnection();

String sql = "insert into userreg (username,password,email) values('" +

this.userName + "','" + this.password + "','" + this.email +

"')";

System.out.println(sql);

try {

Statement stmt = conn.createStatement();

this.count = stmt.executeUpdate(sql);

} catch (SQLException ex) {

ex.printStackTrace();

}

System.out.println( this.count );

}

}

只是 添加用户的方法,用户插入的行数是-1,你们说会不会是myEclipse6.5没有安装好哦,我在其他机子上用5.5打开有是1,不知道为什么。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值