Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String DREIVER = "com.mysql.jdbc.Driver";
- private static final String URL="jdbc:mysql://localhost:3306/jdtest?useUnicode=true&characterEncoding=UTF-8";//链接的mysql
- private static final String NAME = "root";
- private static final String PASSWORD = "";
- private static Connection conn = null;
- static{
- //加载驱动
- Class.forName("com.mysql.jdbc.Driver");
- //获得连接
- conn = DriverManager.getConnection(URL, NAME, PASSWORD);
- }
- try{
- //操作数据库
- Statement stmt = conn.createstatement();
- ResultSet res = stmt.executeQuery("select * from user");
- //光标一行
- while(res.next()){
- res.getString("xxx");
- res.getInt("xxx");
- }
- // 获取PreparedStatement
- String sql = " select * from jdtest.order";
- PreparedStatement ps = conn.prepareStatement(sql);
- ps.execute();
- }catch(Exception e){
- //TODO
- }
Add Comment
Please, Sign In to add comment