📄 insert1.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<HTML>
<head>
<title>The DataBase test</title>
</head>
<BODY>
<%
//驱动程序名、数据库用户名、密码、数据库名、表名
String driverName="com.mysql.jdbc.Driver";
String username="root";
String password="yesterdayn";
String dbName="study";
String tableName="product";
//联结字符串
String url="jdbc:mysql://localhost/"+dbName+"?characterEncoding=GBK";
try{
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//建立同数据库的连接对象
Connection connection=DriverManager.getConnection(url,username,password);
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql1="INSERT INTO "+tableName+"(pdm,pname,provider,info,stock,price)"+
"VALUES('T001','长虹电视','四川长虹','长虹,引领3C未来',129,1999)";
String sql2="INSERT INTO "+tableName+"(pdm,pname,provider,info,stock,price)"+
"VALUES('T002','海信电视','青岛海信','海信,数字高清平板',131,2999)";
//发送执行SQL语句
int n1=statement.executeUpdate(sql1);
int n2=statement.executeUpdate(sql2);
if(n1>0)
out.print("第一条记录插入数据库成功!<BR>");
if(n2>0)
out.print("第二条记录插入数据库成功!<BR>");
statement.close();
connection.close();
}
catch(SQLException e)
{
out.print(e.toString());
}
%>
</HTML>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -