JAVA JDBC代码
时间: 2024-02-18 12:46:00 浏览: 20
示例
这里有一个简单的JDBC示例代码,可以帮助你连接到数据库:
try {
// 加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
// 连接数据库
String url = "jdbc:mysql://localhost:3306/databaseName";
Connection conn = DriverManager.getConnection(url,"username","password");
// 创建SQL语句
String sql = "select * from tableName";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// 处理结果
while (rs.next()) {
// do something
}
// 关闭连接
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
相关问题
java jdbc代码
示例
这里有一个简单的JDBC示例代码,可以帮助你连接到数据库:
try {
// 加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
// 连接数据库
String url = "jdbc:mysql://localhost:3306/databaseName";
Connection conn = DriverManager.getConnection(url,"username","password");
// 创建SQL语句
String sql = "select * from tableName";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// 处理结果
while (rs.next()) {
// do something
}
// 关闭连接
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)