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

java executeupdate,为什么executeUpdate(sql)返回-1呢packagecom.user;importjava.sql.Connection;importjava.sql.Statement;importjava.sql.DriverManager;importjava.sql.*;publicclassuserBean{privateStringuserId;privateStringuserName;privateStrin…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

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,不知道为什么。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/179871.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 用原子操作实现无锁编程[通俗易懂]

    用原子操作实现无锁编程[通俗易懂]假设我们要维护一个全局的线程安全的int类型变量count,下面这两行代码都是很危险的:count++;count+=n;我们知道,高级语言中的一条语句,并不是一个原子操作.比如一个最简单的自增操作就分为三步: 1.从缓存取到寄存器2.在寄存器加13.存入缓存。多个线程访问同一块内存时,需要加锁来保证访问操作是互斥的. 所以,我

    2022年5月27日
    48
  • LoadRunner教程01:性能测试常见用语

    LoadRunner教程01:性能测试常见用语1、并发用户数量:常见的错误理解:使用系统的全部用户数量使用系统的全部在线用户数量正确理解:与服务器进行交互的在线用户数量2、请求响应时间:从client发出请求到得到响应的整个时间,一般包括网络响应时间+server的响应时间3、事务请求响应时间:完成这个事务所用的时间,这个是性能测试中重点关注的指标4、吞吐率:单位时间在网络上传输的数据量(从服务端返

    2022年5月10日
    36
  • PHP curl_init函数——爬虫必备

    PHP curl_init函数——爬虫必备原文地址:http://www.jb51.net/article/25193.htm我们可以使用PHP的扩展库-Curl,这个扩展库通常是默认在安装包中的,你可以它来获取其他站点的内容,也可以来干别的。 备注:这两段代码需要php_curl扩展库的支持,查看phpinfo(),如果curlsupport enabled则表示支持curl库。 1、Windows下的PHP开启curl库

    2022年7月12日
    19
  • pycharm for mac安装

    pycharm for mac安装http www xue51 com mac 5604 html 转载于 https www cnblogs com LeesinDong p 10835539 html

    2025年6月7日
    2
  • c语言中的位移位操作

    c语言中的位移位操作

    2021年12月2日
    41
  • IDEA 激活 服务器 2022.01(JetBrains全家桶)

    (IDEA 激活 服务器 2022.01)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlGTRPTN90LV-eyJsaWN…

    2022年3月31日
    736

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号