要查询表中的所有数据,可以使用 sql 语句 SELECT * FROM table_name; 其中 table_name
要查询表中的所有数据,可以使用 sql 语句 SELECT * FROM table_name; 其中 table_name 是你要查询的表名。以下是一个使用 JDBC 进行查询的示例代码:
import java.sql.*;
public class Main {
public static void main(String[] args) {
String url = "jdbc:Mysql://localhost:3306/database_name";
String username = "username";
String passWord = "password";
try {
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
String query = "SELECT * FROM table_name";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
// 获取每一行数据的值
int id = rs.getInt("id");
String name = rs.getString("name");
int age = rs.getInt("age");
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
--结束END--
本文标题: jdbc怎么查询表中所有数据
本文链接: https://www.lsjlt.com/news/589801.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0