1、创建了表后你可以使用ASP,PHP,NET,JSP等语言去进行数据的增删改
2、相关知识:IIS(或APACHE)+asp(或PHP,NET,JSP)+mssql,(或MYSQL)如果你使用APACHE,那么就只能使用PHP或JSP
3、你的要求必须要使用动态语言和数据库
//User 用户的基本信息,也是USERINFO表中的3个列
package
登陆判断;
public class User {
private String name;
private String loginname;
private String
loginpsw;
public String getName() {
return name;
}
public
void setName(String name) {
thisname = name;
}
public String
getLoginname() {
return loginname;
}
public void
setLoginname(String loginname) {
thisloginname =
loginname;
}
public String getLoginpsw() {
return
loginpsw;
}
public void setLoginpsw(String loginpsw)
{
thisloginpsw = loginpsw;
}
}
//用于注册和登陆的小小代码块
package
登陆判断;
import javautilScanner;
public class In {
public static User getUser(){
User u = new User();
Scanner sc =
new
Scanner(Systemin);
Systemoutprintln("请输入登陆名");
usetLoginname(scnextLine());
Systemoutprintln("请输入密码");
usetLoginpsw(scnextLine());
return
u;
}
public static User registerUser(){
User u = new
User();
Scanner sc = new
Scanner(Systemin);
Systemoutprintln("请注册用户名名");
usetName(scnextLine());
Systemoutprintln("请注册登陆名");
usetLoginname(scnextLine());
Systemoutprintln("请注册密码");
usetLoginpsw(scnextLine());
return
u;
}
}
//登陆时的检查,判断登陆名和密码是否正确,正确则返回 用户名
package 登陆判断;
import javasqlConnection;
import javasqlDriverManager;
import
javasqlPreparedStatement;
import javasqlResultSet;
import
javasqlSQLException;
public class Check {
public static void checkUser(User u)
{
try
{
ClassforName("oraclejdbcdriverOracleDriver");
} catch
(ClassNotFoundException e) {
eprintStackTrace();
}
String
url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user =
"scott";
String password = "tiger";
Connection conn =
null;
ResultSet rs = null;
PreparedStatement pst =
null;
String sql = "Select name from USERINFO where loginname = and
loginpsw = ";
try {
conn = DriverManagergetConnection(url, user,
password);
pst = connprepareStatement(sql);
pstsetString(1,
ugetLoginname());
pstsetString(2,ugetLoginpsw());
rs =
pstexecuteQuery();
while(rsnext()){
usetName(rsgetString(1));
}
}
catch (SQLException e) {
eprintStackTrace();
}finally{
try
{
rsclose();
pstclose();
connclose();
} catch
(SQLException e)
{
eprintStackTrace();
}
}
if(ugetName() == null ||
ugetName()isEmpty()){
Systemoutprintln("登陆失败");
}else{
Systemoutprintln("欢迎"+ugetName()+"登陆");
}
}
}
//注册界面,要判断 登陆名是否有重复,有重复则注册失败。有点小疑问,已用注释标出来
package 登陆判断;
import javasqlConnection;
import javasqlDriverManager;
import
javasqlPreparedStatement;
import javasqlResultSet;
import
javasqlSQLException;
import javasqlStatement;
public class Register {
public static void registUser(User u){
try
{
ClassforName("oraclejdbcdriverOracleDriver");
} catch
(ClassNotFoundException e) {
eprintStackTrace();
}
String
url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user =
"scott";
String password = "tiger";
Connection conn =
null;
String sql = "Insert Into USERINFO
values(,,)";
PreparedStatement pst =
null;
//判断登陆名是否已经存在
Statement s = null;
ResultSet rs =
null;
String sql_ck = "Select LOGINNAME FROM USERINFO";
try
{
conn = DriverManagergetConnection(url, user, password);
pst =
connprepareStatement(sql);
pstsetString(1,
ugetName());
pstsetString(2, ugetLoginname());
pstsetString(3,
ugetLoginpsw());
//判断登陆名是否已经存在
s =
conncreateStatement();
rs =
sexecuteQuery(sql_ck);
while(rsnext()){//为什么用 rsgetString(2)会提示
无效的索引呢
if( rsgetString("LOGINNAME")equals(ugetLoginname())
){
Systemoutprintln("登陆名已经存在,注册失败");
break;
}else{
pstexecuteUpdate();
Systemoutprintln("注册成功");
break;
}
}
}
catch (SQLException e) {
eprintStackTrace();
}finally{
try
{
rsclose();
pstclose();
sclose();
connclose();
}
catch (SQLException e)
{
eprintStackTrace();
}
}
}
}
//main界面//
//数据库中表的结构式这样
//name(用户名,用于显示),
//loginname(登录名,即登陆时输入的ID)
//loginpsw(登陆时输入的密码)
package
登陆判断;
import javautilScanner;
public class Test {
public static void main(String[] args) {
int chos = 0;
Scanner sc = new
Scanner(Systemin);
Systemoutprintln("\t\t登陆请按1\t\t注册请按2");
chos =
scnextInt();
switch(chos){
case 1:
CheckcheckUser(IngetUser());break;
case 2:
RegisterregistUser(InregisterUser());break;
default:
Systemoutprintln("请输入正确的选择");break;
}
}
}
简单的代码
你看看
1 登陆前台代码
<form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="用户:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="登陆" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="注册" />
</div>
</form>
登陆判断后台代码
protected void Button1_Click(object sender, EventArgs e){
UserInfo info = new UserInfo();
infoName = thisTextBox1TextTrim();
infoPass = thisTextBox2TextTrim();
//用户登陆验证
if (UserBLLLogin(info))
{
ResponseRedirect("Default2aspx");
}
else
{
ResponseWrite("<script>alert('登陆错误');</script>");
thisTextBox1Text = "";
thisTextBox2Text = "";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
ResponseRedirect("Default3aspx");
}
我的textbox验证是在后台验证。你可以用JS在前台验证。判断是否空等等
注册前台:
<form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="姓名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="性别:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="返回登陆" onclick="Button2_Click"
style="height: 26px" />
</div>
注册后台代码:
protected void Button1_Click(object sender, EventArgs e){
UserInfo info = new UserInfo();
infoName = thisTextBox1TextTrim();
infoPass = thisTextBox2TextTrim();
infoSex = thisTextBox3TextTrim();
//注册
UserBLLInsert(info);
ResponseWrite("<script>alert('注册成功');</script>");
thisTextBox1Text = "";
thisTextBox2Text = "";
thisTextBox3Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
ResponseRedirect("Defaultaspx");
} //数据库 *** 作login是登陆,insert是注册
public bool Login(UserInfo info)
{
string sql =stringFormat("pro_Login");
SqlParameter[] values = new SqlParameter[] { new SqlParameter("@name", infoName), new SqlParameter("@pass", infoPass) };
int result = ConvertToInt32(DBHlpergetSR(sql, values));
if (result > 0)
{
return true;
}
else
{
return false;
}
}
public int Insert(UserInfo info)
{
string sql = stringFormat("pro_Insert");
SqlParameter[] values = new SqlParameter[] { new SqlParameter("@name", infoName), new SqlParameter("@pass", infoPass), new SqlParameter("@sex", infoSex) };
int resulut = ConvertToInt32(DBHlpergetEQ(sql, values));
return resulut;
}
我用的是存储过程,你可以不用存储过程
如:登陆
public bool Login(string name,string pwd){
string sql =“select from 表 where username=”+name"+" and pwd="pwd;
}
// 很灵活随意写,数据库我自己找不到了,设计的话也很简单
//给你个思路,用户表, userid username pwd
//userid 自动增长 注册登陆用这张表即可,如果还有什么相关的表,即用userid去关联
//如:用户成绩表 id userid chengji
//查询数据 用用户表的userid去关联成绩表的userid就可以
以上就是关于做网站时想用数据库,想实现留言板和注册登录功能想实现发贴功能全部的内容,包括:做网站时想用数据库,想实现留言板和注册登录功能想实现发贴功能、求用java实现简单的登录和注册功能,主要是为了了解怎样对数据库进行增删改查。和各种请求处理,、完成用户登录和用户注册功能(可以用asp.net+sqlserver2000/2005/2008或jsp+oracle/mysql完成)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)