当前位置:首页 » 编程语言 » jspsql

jspsql

发布时间: 2022-06-27 22:39:05

① Jsp中的sql语句写法,高手进哦~~

String sql = "select * from record where choice like '"+%gjz%+"' and date >= '"+sdate+"' and date <='"+edate+"' order by date ";

ResultSet rs=stmt.executeQuery(sql);
'"+%gjz%+"'没有错

② jsp的sql语句的写法

SELECT * FROM 表名 WHERE Index_img!=''
SELECT * FROM 表名 WHERE Index_img!='' AND User_Name='用户名'
SELECT * FROM 表名 WHERE Index_img!='' AND News_Class='新闻分类'
SELECT * FROM 表名 WHERE User_Name='用户名'
SELECT * FROM 表名 WHERE News_Class='新闻分类'

③ jsp连接sql数据库,并用jsp把数据导入数据库中

JSP连接SQL数据库实现查找(支持模糊查找,查找年龄段),插入信息<实例>

<h2>学生信息查询</h2>

<form method="POST" action="Name.jsp">
<h4>按姓名查找(支持模糊查询)</h4>
<table bgcolor="#CCCCCC">
<tr>
<td>查找姓名</td>
<td><input type="text" name="name" size="15" /></td>
<td><input type="submit" value="查找"></td>
</tr>
</table>
</form>
<br/>

<form method="POST" action="Age.jsp">
<h4>按年龄查找</h4>
<table border="1" bgcolor="#CCCCCC">
<tr>
<td>查找年龄</td>
<td><input type="text" name="agemin" size="5" /></td>
<td>到</td>
<td><input type="text" name="agemax" size="5" /></td>
<td><input type="submit" value="查找"></td>
</tr>
</table>
</form>

<form action="Insert.jsp" method="POST">
<h4>插入信息到表中</h4>
<table border="1" bgcolor="#cccccc">
<tr>
<td>姓名</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>性别</td>
<td><input type="text" name="sex" /></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" name="age" /></td>
</tr>
<tr>
<td>系别</td>
<td><input type="text" name="dept" /></td>
</tr>
<tr>
<td><input type="submit" value="插入" /></td>
<td><input type="reset" value="重置" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>

④ 如何在jsp中执行多条sql语句

jsp同时执行多条sql,需要封装成存储过程,否则效率很低,甚至会引起性能问题。
jsp触发后台java调用存储过程的例子:

进行调用的详细代码:
try{
int age = 39;
String poetName = "dylan thomas";
CallableStatement proc = connection.prepareCall("{ call set_death_age(?, ?) }");
proc.setString(1, poetName);
proc.setInt(2, age);
cs.execute();
}catch (SQLException e){ // ....}
传给prepareCall方法的字串是存储过程调用的书写规范。它指定了存储过程的名称,?代表了需要指定的参数。

⑤ 如何用JSP连接SQL数据库..

你好,1.将数据库驱动程序的JAR文件放在Tomcat的 common/lib 中;
2.在server.xml中设置数据源,以MySQL数据库为例,如下:
在<GlobalNamingResources> </GlobalNamingResources>节点中加入,
<Resource
name="jdbc/DBPool"
type="javax.sql.DataSource"
password="root"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://127.0.0.1:3306/test"
maxActive="4"/>
属性说明:name,数据源名称,通常取”jdbc/XXX”的格式;
type,”javax.sql.DataSource”;
password,数据库用户密码;
driveClassName,数据库驱动;
maxIdle,最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连
接将被标记为不可用,然后被释放。设为0表示无限制。
MaxActive,连接池的最大数据库连接数。设为0表示无限制。
maxWait ,最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示
无限制。
3.在你的web应用程序的web.xml中设置数据源参考,如下:
在<web-app></web-app>节点中加入,
<resource-ref>
<description>MySQL DB Connection Pool</description>
<res-ref-name>jdbc/DBPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
子节点说明: description,描述信息;
res-ref-name,参考数据源名字,同上一步的属性name;
res-type,资源类型,”javax.sql.DataSource”;
res-auth,”Container”;
res-sharing-scope,”Shareable”;
4.在web应用程序的context.xml中设置数据源链接,如下:
在<Context></Context>节点中加入,
<ResourceLink
name="jdbc/DBPool"
type="javax.sql.DataSource"
global="jdbc/DBPool"/>
属性说明:name,同第2步和第3步的属性name值,和子节点res-ref-name值;
type,同样取”javax.sql.DataSource”;
global,同name值。

至此,设置完成,下面是如何使用数据库连接池。
1.建立一个连接池类,DBPool.java,用来创建连接池,代码如下:
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBPool {
private static DataSource pool;
static {
Context env = null;
try {
env = (Context) new InitialContext().lookup("java:comp/env");
pool = (DataSource)env.lookup("jdbc/DBPool");
if(pool==null)
System.err.println("'DBPool' is an unknown DataSource");
} catch(NamingException ne) {
ne.printStackTrace();
}
}
public static DataSource getPool() {
return pool;
}
}

2.在要用到数据库操作的类或jsp页面中,用DBPool.getPool().getConnection(),获得一个Connection对象,就可以进行数据库操作,最后别忘了对Connection对象调用close()方法,注意:这里不会关闭这个Connection,而是将这个Connection放回数据库连接池。 22723希望对你有帮助!

⑥ jsp中sql语句

确定在SQL 2000查询分析器中,没有问题吗.那你就试试把查询结果放到临时表里,再查询排序?select ResumeNum,Favorites.ResumeName,TrueName,Sex,Mobile_Phone,School,Professional,Degree,Scoree,Statusinto #a from Favorites,Resume_Basic,Resume_Ecation,Resume_Language,Resume_Rewards_Punish where Favorites.ResumeName = Resume_Basic.UserName and Resume_Basic.UserName=Resume_Ecation.UserName and Resume_Rewards_Punish.UserName =Resume_Basic.UserName and Resume_Language.UserName= Resume_Basic.UserName and Resume_Ecation.ID='0001'and Favorites.CompanyNum='222' select * from #a order by Scoreedrop table #a----笨法子

⑦ jsp怎么连接sql数据库

1.将数据库驱动程序的JAR文件放在Tomcat的 common/lib 中; 2.在server.xml中设置数据源,以MySQL数据库为例,如下: 在 节点中加入, 属性说明:name,数据源名称,通常取”jdbc/XXX”的格式; type,”javax.sql.DataSource”; password,数据库用户密码; driveClassName,数据库驱动; maxIdle,最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连 接将被标记为不可用,然后被释放。设为0表示无限制。 MaxActive,连接池的最大数据库连接数。设为0表示无限制。 maxWait ,最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示 无限制。 3.在你的web应用程序的web.xml中设置数据源参考,如下: 在节点中加入, MySQL DB Connection Pool jdbc/DBPool javax.sql.DataSource Container Shareable 子节点说明: description,描述信息; res-ref-name,参考数据源名字,同上一步的属性name; res-type,资源类型,”javax.sql.DataSource”; res-auth,”Container”; res-sharing-scope,”Shareable”; 4.在web应用程序的context.xml中设置数据源链接,如下: 在节点中加入, 属性说明:name,同第2步和第3步的属性name值,和子节点res-ref-name值; type,同样取”javax.sql.DataSource”; global,同name值。 至此,设置完成,下面是如何使用数据库连接池。 1.建立一个连接池类,DBPool.java,用来创建连接池,代码如下: import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; public class DBPool { private static DataSource pool; static { Context env = null; try { env = (Context) new InitialContext().lookup("java:comp/env"); pool = (DataSource)env.lookup("jdbc/DBPool"); if(pool==null) System.err.println("'DBPool' is an unknown DataSource"); } catch(NamingException ne) { ne.printStackTrace(); } } public static DataSource getPool() { return pool; } } 2.在要用到数据库操作的类或jsp页面中,用DBPool.getPool().getConnection(),获得一个Connection对象,就可以进行数据库操作,最后别忘了对Connection对象调用close()方法,注意:这里不会关闭这个Connection,而是将这个Connection放回数据库连接池。

⑧ java在jsp页面如何直接执行sql

两个简单的jsp页面,数据库连接(我给你的是mysql数据库连接示例,后面附sqlserver数据库连接部分关键代码)
首先是 获取值页面My.jsp 源码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'My.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="Hp.jsp">
name:<input name="name" value="" type="text"></br>
password:<input name="password" value="" type="text"></br>
<input type="submit" value="button">
</form>
</body>
</html>
处理页面 Hp.jsp 源码:
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Hp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
Connection con = null;
Statement stm = null;

String url = "jdbc:mysql://localhost:3306/数据名称";//数据库名称就是你的数据库名字
String driver = "com.mysql.jdbc.Driver"; //驱动类位置
String username = "root"; //数据库登录名称,此处写上你的用户名称
String pwd = "root"; //数据库登录密码,此处写上你的登录密码
try
{
Class.forName(driver);
con = DriverManager.getConnection(url, username, pwd); //创建Connection连接对象
stm = con.createStatement(); //创建Statement 命令执行对象
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

String name=request.getParameter("name"); //获取传过来的名称
String password=request.getParameter("password");//获取传过来的密码

String sql="insert into user(name,password) values("+name+","+password+")";//数据库添加一条记录sql语句

int temp=stm.executeUpdate(sql);

if(temp>0)
{
out.print("添加成功");
}
else
{
out.print("添加失败");
}
//关闭数据库连接
stm.close();
con.close();

%>
</body>
</html>
注意 连接不同数据库要导入不同的数据库驱动包 你要导入才行啊
附 sqlserver数据库连接 部分关键代码:
private static Connection con = null;
private static Statement stm = null;

private static String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=数据库名称";
private static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";//与mysql有所不同
private static String username = "sa";//默认用户
private static String pwd = "123"; //密码

static {
try {
Class.forName(driver);

con = DriverManager.getConnection(url, username, pwd);
System.out.print("连接成功!");
stm = con.createStatement();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

热点内容
c语言中的整型 发布:2025-03-16 06:40:48 浏览:183
分部数据库服务器的IP地址有效 发布:2025-03-16 06:33:40 浏览:191
安卓项目如何配置tomacat 发布:2025-03-16 06:31:13 浏览:430
写脚本测试 发布:2025-03-16 06:20:07 浏览:780
多个拨号宽带如何配置 发布:2025-03-16 05:51:35 浏览:688
管理员c语言 发布:2025-03-16 05:40:17 浏览:342
安卓软件上的图案如何更改 发布:2025-03-16 05:35:57 浏览:748
2010编译c中文乱码 发布:2025-03-16 05:33:40 浏览:550
干一杯密码箱酒多少钱一箱 发布:2025-03-16 05:31:15 浏览:358
我的零钱通密码是多少 发布:2025-03-16 05:04:36 浏览:938