标题:sql 删除表格里面的用户和修改密码的问题
只看楼主
jouniwei
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-4-3
 问题点数:0 回复次数:1 
sql 删除表格里面的用户和修改密码的问题
package com.demo.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.PreparedStatement;

public class JdbcConnectMain {

    public static void main(String[] args) throws Exception, IllegalAccessException, ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        
        Connection con = java.sql.DriverManager
                .getConnection(
                        "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK",
                        "root", "123456");
        readDataFromDB(con);
        
        insertInto(con);
        
        // delete,update
        // badqiu的密码改成为123456;用到数据库的UPDATE功能
        // 把用户名jz删除
    }

    private static void insertInto(Connection con) throws SQLException {
        java.sql.PreparedStatement ps = con.prepareStatement("insert into user(username,pwd) values (?,?)");
        ps.setString(1, System.currentTimeMillis()+"");
        ps.setString(2, "pwd_123456");
        ps.execute();
    }

    private static void readDataFromDB(Connection con) throws SQLException {
        Statement stmt = null;
        ResultSet rst = null;
        
        try {
            stmt = con.createStatement();
            rst = stmt.executeQuery("select * from user");
            
            while(rst.next()) {
                System.out.println("username:"+rst.getString(1)+" pwd:"+rst.getString("pwd"));
            }
        }finally {
            stmt.close();
            rst.close();
        }
        
    }

}
搜索更多相关主题的帖子: 修改密码 public 表格 package 
2012-07-03 00:17
别时茫茫
Rank: 2
来 自:安徽蚌埠
等 级:论坛游民
威 望:1
帖 子:29
专家分:72
注 册:2011-10-5
得分:0 
what question
setString(1,"")
setString(2,"");
好像是从0开始的。
2012-11-28 18:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-372689-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.261304 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved