zoukankan
html css js c++ java
jsp+mysql 数据库操作
package
test;
import
java.sql.
*
;
public
class
Conn
{
static
String data
=
"
jdbc:mysql://localhost/first
"
;
static
java.sql.Statement st;
public
static
void
databaseconnect()
{
//
函数用于 连接数据库
try
{
Class.forName(
"
com.mysql.jdbc.Driver
"
);
Connection conn
=
DriverManager.getConnection(data,
"
root
"
,
"
root
"
);
st
=
conn.createStatement();
}
catch
(Exception e)
{
System.out.println(
"
异常:
"
+
e.toString());
}
}
public
static
String pwquery(String name)
{
databaseconnect();
String inname
=
name;
String pw
=
""
;
ResultSet rs
=
null
;
try
{
rs
=
((java.sql.Statement) st).executeQuery(
"
select * from test2 where name='
"
+
name
+
"
'
"
);
while
(rs.next())
{
pw
=
rs.getString(
"
pass
"
);
}
rs.close();
st.close();
//
pw="abc";
}
catch
(SQLException e)
{
e.printStackTrace();
}
return
pw;
}
}
<?
xml version="1.0" encoding="gb2312"
?>
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=gb2312
"
%>
<%
@page import
=
"
test.Conn
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=ISO-8859-1"
/>
<
title
>
test
</
title
>
</
head
>
<
body
>
<%
String
temp
=
(
String
)session.getValue(
"
login
"
);
temp
=
Conn.pwquery(
"
admin
"
);
//
out.print(temp);
out.print(temp);
%>
</
body
>
</
html
>
注意把
tomcat\common\lib
添加
mysql-connector-java-5.0.8-bin.jar
查看全文
相关阅读:
Cannot find a free socket for the debugger
如何让myeclipse左边选中文件后自动关联右边树
myeclipse反编译安装 jd-gui.exe下载
MyEclipse报错Access restriction: The type BASE64Encoder is not accessible due to restriction on required library
如何使用JAVA请求HTTPS
如何使用JAVA请求HTTP
SVN提交代码时报405 Method Not Allowed
对称加密和非对称加密
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
调整Linux操作系统时区-centos7
原文地址:https://www.cnblogs.com/gwazy/p/953622.html
最新文章
到底啥是w3c标准
JavaScript(六)函数
JavaScript(五)语句
JavaScript(四)操作符
JavaScript(三) 数据类型
console报错类型
JavaScript(二)基本概念
JavaScript(一)js简单介绍
CSS(五)圣杯,双飞翼布局
SpringAOP事务管理
热门文章
Java多线程学习
maven pom.xml文件教程详解
IO流常用方法,流的用法,代码例子
ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY
jndi总结
JVM内存堆布局图解分析
Java面向对象六大原则
实现线程同步的方式,以及区别
什么是高并发,如何避免高并发
tomcat闪退无法启动 the catalina_home environment variable is not defined correctly this environment variable is needed to run this program
Copyright © 2011-2022 走看看