生活随笔
收集整理的這篇文章主要介紹了
Jdbc创建表 利用循环添加数据 ,更新数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一:上碼
1.有的已經實現的就注釋了
2.配置文件信息
package com.wyjedu.jdbc.PreparedStatement;import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.Scanner;public class preparedStatement03
{public static void main(String[] args
) throws Exception{text01();}public static void text01() throws Exception{Properties properties
= new Properties();properties
.load(new FileInputStream("src//mysql.properitys"));String url
= properties
.getProperty("url");String user
= properties
.getProperty("user");String password
= properties
.getProperty("password");String driver
= properties
.getProperty("driver");Class.forName(driver
);Connection connection
= DriverManager.getConnection(url
, user
, password
);String sql
= "select * from admin";PreparedStatement preparedStatement
= connection
.prepareStatement(sql
);Scanner scanner
= new Scanner(System.in
);
ResultSet resultSet
= preparedStatement
.executeQuery();while(resultSet
.next()){int id
= resultSet
.getInt(1);String name
= resultSet
.getString(2);System.out
.println(id
+" "+name
);}resultSet
.close();preparedStatement
.close();connection
.close();}
}
總結
以上是生活随笔為你收集整理的Jdbc创建表 利用循环添加数据 ,更新数据的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。