JSP程序毗邻MySQL新建数据表和更新表数据的示例代

日期:2014-07-13 / 人气: / 来源:网络

1,jsp建立数据表
<html>
<head>
</head>
<body>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com. mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="root";
//数据库名
String dbName="test";
//表名
String tableName="user";
//联结字符串
String url="jdbc:mysql://localhost/" dbName "?user=" userName "&password=" userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="create table haisen(id int)";
int rs = statement.executeUpdate(sql);
statement.close();
connection.close();
int tryint[]=new int[2];
tryint[0]=1;
tryint[1]=2;
%>
</body>
<script>
var aaatry="<%=rs%>";
alert(aaatry);
</script>
</html>

2,jsp向数据库中插入数据
<html>
<head>
</head>
<body>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="root";
//数据库名
String dbName="test";
//表名
String tableName="user";
//联结字符串
String url="jdbc:mysql://localhost/" dbName "?user=" userName "&password=" userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="insert table user values('2','haisen')";
int rs = statement.executeUpdate(sql);
statement.close();
connection.close();
int tryint[]=new int[2];
tryint[0]=1;
tryint[1]=2;
%>
</body>
<script>
var aaatry="<%=rs%>";
alert(aaatry);
</script>
</html>

MySQL数据库中触发器的使用方法

在mysql触发器数据库的使用过程中,mysql触发器是经常用到的,下面就为您介绍mysql触发器从创建到使用的全过程,供您参考学习。1、在安装了最新版本后,你必须运行:mysql_fix_privilege_tables或者mysql_install_db(

MySQL

作者:管理员




现在致电4006-2991-90 OR 查看更多联系方式 →

Go To Top 回顶部