Java:为什么resultser.next() ==false?我的数据库里有数据
代码:
import java.lang.String;
import java.sql.*;
//import java.util.Properties;
public class Jdbctext1 {
public static void main(String[] args)throws SQLException
{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
Class.forName("com.mysql.jdbc.Driver");//驱动
System.out.println("loading success!");
String url = "jdbc:mysql://localhost:3306/Library?useUnicode=true&characterEncoding=utf-8&useSSL=false";
String user = "root";
String passward = "123456";
conn =DriverManager.getConnection(url,user,passward);//connection对象
String sql = "select * from users";
stmt = conn.prepareStatement(sql);//statement对象
rs = stmt.executeQuery();
System.out.println("id | name | passward | email | birthday");
if(rs.next()==false)System.out.println("false!");//re.next()一直等于false
while(rs.next())//进不去该循环
{
System.out.println("test");
int id = rs.getInt("id");
String name =rs.getString("name");
String psw =rs.getString("passward");
String email = rs.getString("email");
Date birthday = rs.getDate("birthday");
System.out.println(id + "|"+ name + "|" + psw+ "|" +email + "|" +birthday);
}
/******************** 下面不重要 *************************************/
System.out.println("connecting success!");
}catch(Exception e)
{
System.out.println("123");
e.printStackTrace();
}finally {
if(rs!=null) {
try
{
rs.close();
}catch(SQLException e)
{
e.printStackTrace();
}
rs=null;
}
if(stmt!=null) {
try
{
stmt.close();
}catch(SQLException e)
{
e.printStackTrace();
}
stmt=null;
}
if(conn!=null) {
try
{
conn.close();
}catch(SQLException e)
{
e.printStackTrace();
}
conn=null;
}
}
}
}
JAR

console:
import java.lang.String;
import java.sql.*;
//import java.util.Properties;
public class Jdbctext1 {
public static void main(String[] args)throws SQLException
{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
Class.forName("com.mysql.jdbc.Driver");//驱动
System.out.println("loading success!");
String url = "jdbc:mysql://localhost:3306/Library?useUnicode=true&characterEncoding=utf-8&useSSL=false";
String user = "root";
String passward = "123456";
conn =DriverManager.getConnection(url,user,passward);//connection对象
String sql = "select * from users";
stmt = conn.prepareStatement(sql);//statement对象
rs = stmt.executeQuery();
System.out.println("id | name | passward | email | birthday");
if(rs.next()==false)System.out.println("false!");//re.next()一直等于false
while(rs.next())//进不去该循环
{
System.out.println("test");
int id = rs.getInt("id");
String name =rs.getString("name");
String psw =rs.getString("passward");
String email = rs.getString("email");
Date birthday = rs.getDate("birthday");
System.out.println(id + "|"+ name + "|" + psw+ "|" +email + "|" +birthday);
}
/******************** 下面不重要 *************************************/
System.out.println("connecting success!");
}catch(Exception e)
{
System.out.println("123");
e.printStackTrace();
}finally {
if(rs!=null) {
try
{
rs.close();
}catch(SQLException e)
{
e.printStackTrace();
}
rs=null;
}
if(stmt!=null) {
try
{
stmt.close();
}catch(SQLException e)
{
e.printStackTrace();
}
stmt=null;
}
if(conn!=null) {
try
{
conn.close();
}catch(SQLException e)
{
e.printStackTrace();
}
conn=null;
}
}
}
}
JAR

console:

...全文
相关推荐
Java 程序显示 hasNext() 和 next() 方法的用法.docx
Java是一种功能强大、可靠性高、跨平台的编程语言,适用于各种应用场景。它被广泛用于企业级应用开发、移动应用开发、云计算、大数据处理等领域,是一门值得学习和掌握的编程语言。
Java源码解析HashMap的keySet()方法
今天小编就为大家分享一篇关于Java源码解析HashMap的keySet()方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
Java动态数组添加数据的方法与应用示例
主要介绍了Java动态数组添加数据的方法,结合实例形式详细分析了Java动态数组的创建、添加、查找、打印等相关操作技巧,需要的朋友可以参考下
java sql ResultSet 之getRow()用法说明
主要介绍了java sql ResultSet 之getRow()用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Java中Boolean与字符串或者数字1和0的转换实例
下面小编就为大家带来一篇Java中Boolean与字符串或者数字1和0的转换实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧


Java SE
