c#连接oracle数据库实现登陆功能

c#连接oracle数据库实现登陆功能,第1张

connString= string.Format("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER={2})(SERVICE_NAME={3})))User Id={4}Password={5}Pooling=trueMax Pool Size=100"

, stxtIP.Text.Trim(), stxtPort.Text.Trim(), stxtIP.Text.Trim(), stxtSID.Text.Trim(), stxtUserID.Text.Trim(), stxtPwd.Text.Trim())

//验证用户和密码

@Override

public int queryUser(UserVo vo) {

// TODO Auto-generated method stub

Connection conn = null

PreparedStatement stmt = null

ResultSet rs = null

String sql = "select count(*) from user_info where username=? and password=?"

int count = 0

try{

//获取连接对像

conn = ConnTools.getConnection()

//获取stmt

stmt = conn.prepareStatement( sql )

//设置动态参数

stmt.setString( 1, vo.getUsername() )

stmt.setString( 2, vo.getPassword() )

//执行查询

rs = stmt.executeQuery()

if( rs.next() ){

count = rs.getInt( 1 )

}

}catch( Exception e ){

e.printStackTrace()

}finally{

//释放资源

ConnTools.close(conn, stmt, rs)

}

return count

}

//这是我以前写的核对数据库实现登陆的方法,你只看jdbc部分就好,我还特地给你加了点注释\x0d\x0aString sql = "select username,password from account"\x0d\x0aString user = request.getParameter("user")\x0d\x0aString pass = request.getParameter("password")\x0d\x0aint j = 0\x0d\x0aConnection conn = null\x0d\x0aPreparedStatement ps = null\x0d\x0aResultSet rs = null\x0d\x0atry {\x0d\x0aconn = JDBCTools1.getConnection()\x0d\x0aps = conn.prepareStatement(sql)\x0d\x0ars = ps.executeQuery()\x0d\x0a//从表中查询获取所有账户的用户名&密码的ResultSet 对象\x0d\x0awhile(rs.next()){\x0d\x0aint i = 0\x0d\x0a\x0d\x0aString username[] = new String[10]//用户名数组\x0d\x0aString password[] = new String[10]//密码数组\x0d\x0ausername[i] = rs.getString(1)\x0d\x0apassword[i] = rs.getString(2)\x0d\x0aif(user.equals(username[i])&&pass.equals(password[i])){//比对\x0d\x0aresponse.getWriter().print("you are welcome!")\x0d\x0aj++\x0d\x0a}else if(user.equals(username[i])&&!pass.equals(password[i])){\x0d\x0aresponse.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n")\x0d\x0aresponse.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right")\x0d\x0aj++\x0d\x0a}else{\x0d\x0acontinue\x0d\x0a}\x0d\x0ai++\x0d\x0a}\x0d\x0aif(j == 0){\x0d\x0aresponse.getWriter().println("Your username may not be properly")\x0d\x0a}\x0d\x0a} catch (Exception e) {\x0d\x0ae.printStackTrace()\x0d\x0a}finally{\x0d\x0aJDBCTools1.release(rs, ps, conn)\x0d\x0a}\x0d\x0a//这是我JDBCTools的getConnection方法\x0d\x0agetConnection{\x0d\x0aString driverClass = oracle.jdbc.driver.OracleDriver\x0d\x0aString jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl\x0d\x0a//你的数据库的用户名密码\x0d\x0aString user = null\x0d\x0aString password = null\x0d\x0a// 通过反射创建Driver对象\x0d\x0aClass.forName(driverClass)\x0d\x0areturn DriverManager.getConnection(jdbcUrl, user, password)}\x0d\x0a//这是我JDBCTools的release方法\x0d\x0apublic static void release(ResultSet rs, Statement statement,\x0d\x0aConnection conn) {\x0d\x0aif (rs != null) {\x0d\x0atry {\x0d\x0ars.close()\x0d\x0a} catch (SQLException e) {\x0d\x0ae.printStackTrace()\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0aif (statement != null) {\x0d\x0atry {\x0d\x0astatement.close()\x0d\x0a} catch (Exception e2) {\x0d\x0ae2.printStackTrace()\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0aif (conn != null) {\x0d\x0atry {\x0d\x0aconn.close()\x0d\x0a} catch (Exception e2) {\x0d\x0ae2.printStackTrace()\x0d\x0a}\x0d\x0a}\x0d\x0a}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6694923.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存