关于mysql数据库的调用

关于mysql数据库的调用,第1张

//整理了一下代码,改了一个地方:

<php              

include_once('/inc/connphp');

session_start();

$name=$_POST["username"];

$password=$_POST["password"];

$sql="SELECT  FROM users WHERE username='$name' and password ='$password' ";

//echo $sql;

$result = mysql_query($sql);

$row = mysql_fetch_array($result);

if($row){

  $uname=$row['username'];

  $pwd=$row['password'];

  $qxian=$row['quanxian'];

 

  if($name== $uname && $password==$pwd){ //这一行第二个等号是双等号

    $_SESSION['name'] = $uname;

    $_SESSION['islogin']=1;

    if($qxian==1){

      echo "<script>alert('恭喜你,登陆成功!');locationhref='/mainphp';</script>";

    }else{

      echo "<script>alert('恭喜你,登陆成功!');locationhref='/adressListphp';</script>";

    }

  }

}else {

  echo "<script>alert('登陆失败,请检查密码是否正确!');locationhref='/indexphp';</script>";

}

>

1提取单条记录

//importjavasql;

Connectionconn=null;

Statementstmt=null;

ResultSetrs=null;

try{

ClassforName("sunjdbcodbc");

Stringurl="jdbc:odbc:%%1";

con=(url,%%2,%%3);

stmt=conn();

stmt(%%4);

rs=stmt(%%5);

}catch(Exceptione){

e();

}

finally{

try{

if(rs!=null)

rsclose();

if(stmt!=null)

stmtclose();

if(conn!=null)

connclose();

}catch(e){

e();

}

}

3显示表格

/

importjavaawt;

importjavaxswing;

importjavasql;

importjavaxswingtable;

String[]colHeads=%%4;

Connectionconn=null;

Statementstmt=null;

ResultSetrs=null;

try{

ClassforName("sunjdbcodbc");

Stringurl="jdbc:odbc:%%1";

conn=(url,%%2,%%3);

stmt=conn();

rs=stmt("SELECTcount()asau_countfrom"%%5);

rsnext();

intiCount=rsgetInt("au_count");

Object[][]data=newObject[iCount][];

inti=0;

rs=stmt("SELECTfrom"%%5);

while(rsnext()){

data[i]=newObject[iCount];

data[i][0]=rsgetString("au_fname");

data[i][1]=rsgetString("Phone");

data[i][2]=rsgetString("City");

i;

}

JTabletable=newJTable(data,colHeads);

JScrollPanejsp=newJScrollPane(table);

()add(jsp);

}catch(Exceptione){

eprintStackTrace();

}

finally{

try{

if(rs!=null)

rsclose();

if(stmt!=null)

stmtclose();

if(conn!=null)

connclose();

}catch(SQLExceptione){

eprintStackTrace();

}

}

6关闭时关闭连接

//importjavasql;

addWindowListener(newWindowAdapter{

publicvoidwindowClosing(WindowEventwevent){

if(stmt!=null){

try{

if(rs!=null)

rsclose();

if(stmt!=null)

stmtclose();

if(conn!=null)

connclose();

}catch(SQLExceptione){

eprintStackTrace();

}

}

7执行命令

//importjavasql;

Connectionconn=null;

PreparedStatementpst=null;

try{

conn=DriverManagergetConnection(url);

pst=connprepareStatement("InsertIntograde(%%1)Values()");

pstsetInt(1,%%2);

//pstsetString(2,%%2);

pstaddBatch();

pstexecuteBatch();

}catch(SQLExceptione){

eprintStackTrace();

}

finally{

try{

if(pst!=null)

pstclose();

if(conn!=null)

connclose();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

eprintStackTrace();

}

}

以上就是关于关于mysql数据库的调用全部的内容,包括:关于mysql数据库的调用、在Java中如何对数据库中的数据进行 *** 作(java怎么调用数据库里的数据)、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/sjk/10090364.html

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

发表评论

登录后才能评论

评论列表(0条)

保存