67,512
社区成员
发帖
与我相关
我的任务
分享
package com.zyh.service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Project Name: sdut-deliver File name: Updatetable.java
*
* @author : zyh
* @version 创建时间:2017年3月7日 下午6:29:07 TODO
*/
public class Updatetable {
String url = "jdbc:mysql://localhost:3306/sdutEXAM?useSSL=false";
String user = "root";
String password = "root";
String driver = "com.mysql.jdbc.Driver";
Statement stmt;
public void update(String exam_week1, String class_name1, String remarks1) {
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);
if (!conn.isClosed())
System.out.println("Succeeded connecting to the Database!11111");
stmt = conn.createStatement();
String sqlUpdateTable = "update exam set remarks= '" + remarks1 + "' where exam_week = '" + exam_week1
+ "' and class_name = '" + class_name1+"'";
System.out.println("接下来执行更新");
if(stmt.execute(sqlUpdateTable)){
System.out.println("更新完成\n");
}else {
System.out.println("更新出现问题,数据没有更新\n");
}
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
choose = 201701
已经进入Qquery
Succeeded connecting to the Database!
78
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '通信23系' where exam_week='16-4-5、6' and class_name='教4408(西)'
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '基22础许' where exam_week='16-4-5、6' and class_name='教5103(西)'
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '科学' where exam_week='16-4-5、6' and class_name='教5201(西)'
[/quote]
有没有异常出来 你捕获一下 打出来看看choose = 201701
已经进入Qquery
Succeeded connecting to the Database!
78
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '通信23系' where exam_week='16-4-5、6' and class_name='教4408(西)'
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '基22础许' where exam_week='16-4-5、6' and class_name='教5103(西)'
Succeeded connecting to the Database! 更新数据库测试
这是sql执行的过程,查看一下 = update exam set remarks= '科学' where exam_week='16-4-5、6' and class_name='教5201(西)'