📄 create.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 Connection test</title>
</head>
<BODY>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String username="root";
//密码
String password="yesterdayn";
//联结字符串
String url="jdbc:mysql://localhost/";
try{
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//建立同数据库的连接对象
Connection connection=DriverManager.getConnection(url,username,password);
Statement statement = connection.createStatement();
//新建一个数据库
statement.execute("CREATE DATABASE newdb;");
//在新建数据库中新建一个表
statement.execute("USE newdb;");
statement.execute("CREATE TABLE newtable(id int(3),name VARCHAR(10) NOT NULL )TYPE=MyISAM;");
//为表添加一个字段
statement.execute("ALTER TABLE newtable ADD qq VARCHAR(16) NOT NULL");
statement.execute("ALTER TABLE newtable ADD email VARCHAR(16) NOT NULL");
//为表建一个索引
statement.execute("ALTER TABLE newtable ADD INDEX new_index (id)");
statement.close();
connection.close();
out.print("数据库操作成功!");
}
catch(SQLException e)
{
out.print(e.toString());
}
%>
</HTML>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -