import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
//这是一个查询表tbl_books中的数据的代码可以看下
public class Connec {
public static void main(String[] args) {
Connection con=null
Statement st=null
ResultSet rs=null
try {
String sql="select * from tbl_books"
Class.forName("oracle.jdbc.OracleDriver")
con=DriverManager.getConnection("jdbc:oracle:thin:@:1521:orcl", "c##jz", "m1234")
st=con.createStatement()
rs=st.executeQuery(sql)
while(rs.next()){
System.out.println(rs.getString("title"))
}
} catch (Exception e) {
e.printStackTrace()
}
}
}
using System.Data.SqlClientstring strconn="server=(local)database=xwxtuid=数据库用户名pwd=数据库密码"
sqlconnection conn=new sqlconnection(strconn)
string str="select count(*) from denglu where username='"+txtuser.Text+"' and password='"+txtpassword.Text+"'"
SqlCommand cmd=new SqlCommand(str,conn)
conn.open
int count=Convert.ToInt32(cmd.ExecuteScalar())
if(count>0)
{ Response.Redirect("index.aspx")
}
else
{
Response.Write("<script>alert('用户名或密码不正确!')</script>")
}
conn.Close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)