AlexTransformer
2018-11-29 07:10JSP连接数据库插入数据相关问题?
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<html>
<head>
</head>
<%
//request.setCharacterEncoding("utf-8");
//String text = request.getParameter("text");
//加载驱动程序
String driverName="com.mysql.jdbc.Driver";
//数据库信息
String USER = "root";
//密码
String PASS = "sq123456";
String DB_URL="jdbc:mysql://localhost/official_website";
Connection conn = null;
Statement stmt = null;
out.print("连接中......");
try{
// 注册 JDBC 驱动
Class.forName("com.mysql.jdbc.Driver");
out.print("连接成功......");
// 打开链接
conn = DriverManager.getConnection(DB_URL,USER,PASS);
out.print("打开连接......");
stmt = conn.createStatement();
String sql;
sql = "INSERT INTO test_table (context) VALUES('I'm a saver!testing!testing!')";
out.print("读取SQL语句中.......");
stmt.executeUpdate(sql);
out.print("执行完成.......");
out.print("Success!");
out.print(sql);
// 完成后关闭
stmt.close();
conn.close();
}catch(SQLException se){
// 处理 JDBC 错误
se.printStackTrace();
}catch(Exception e){
// 处理 Class.forName 错误
e.printStackTrace();
}finally{
// 关闭资源
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// 什么都不做
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
%>
<body>
</body>
</html>
这个段代码的stmt.executeUpdate(sql);这个段语句不执行也不报错到这就停了。这是为什么?
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- hibernate 不用事务,也提交到了数据库,帮忙看看
- spring
- hibernate
- 0个回答
- JSP里连接数据库实现数据插入出错 求帮助。
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- jsp+servlet实现分页
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- SSH开发输出少内容,发现是插入数据的问题,看看问题在哪儿?
- 企业应用
- 0个回答
- JSP连接数据库插入数据相关问题?
- 数据库
- jsp
- 1个回答
换一换