数据库开发实训(Java篇)代码

关卡一

此图片的alt属性为空;文件名为3330448488.png

让我们愉快的(复制粘贴)开始吧!

 //请在此处补全创建数据库实例的SQL语句,不要改动其他代码
/******* Begin ******/
String sqlScript = "create database " + databaseName;

/******* End ******/

运行截屏:

此图片的alt属性为空;文件名为1915187606.png

关卡二

此图片的alt属性为空;文件名为2032901209.png

让我们愉快的(复制粘贴)开始吧!

//请在此处补全创建表的SQL语句,不要改动其他代码
/******* Begin ******/
String sqlScript = "create table " + tableName + "(\n";
for(int k=0; k<tableInfo.length; k++){
if(tableInfo[k][0].equals(""))
break;
sqlScript = sqlScript + tableInfo[k][0] + " " + tableInfo[k][4] + ",\n";
}
sqlScript = sqlScript.substring(0, sqlScript.length()-2);
sqlScript = sqlScript + ")";
/******* End ******/

运行截屏:

此图片的alt属性为空;文件名为3580971980.png

关卡三

此图片的alt属性为空;文件名为4218491025.png

让我们愉快的(复制粘贴)开始吧!

//请在此处补全查询数据的SQL语句,不要改动其他代码
/******* Begin ******/
String sqlScript = "select distinct(publisher) from " + tableName + " where title = \'" + bookName + "\'";
/******* End ******/

运行截屏:

此图片的alt属性为空;文件名为3588862339.png

关卡四

此图片的alt属性为空;文件名为2519859285.png

让我们愉快的(复制粘贴)开始吧!

//请在此处补全向指定表插入数据的SQL语句,不要改动其他代码
/******* Begin ******/
String sqlScript = "Insert into book(id,title,author,publisher,publishYear)" + " values" + "(" + id +"," +"\'" + title+ "\',\'" + author + "\',\'" + publisher + "\',\'" + year + "\')";
/******* End ******/

运行截屏:

此图片的alt属性为空;文件名为374708672.png

关卡五

此图片的alt属性为空;文件名为1830118056.png

让我们愉快的(复制粘贴)开始吧!

public int deleteRecordByAuthor(Connection connection, String tableName,String author){ 
// 请在此处添加数据库删除记录的实现代码
Statement stmt = null;
int updatedNum = 0;
// 删除数据表中数据的SQL语句
String sqlScript = "delete from " + tableName + " where author = \'" + author +"\'";
try {
stmt = connection.createStatement();
updatedNum = stmt.executeUpdate(sqlScript);
} catch (SQLException e) {
e.printStackTrace();
}
return updatedNum;
}


运行截屏:

此图片的alt属性为空;文件名为417909325.png

关卡六

此图片的alt属性为空;文件名为3771854348.png

让我们愉快的(复制粘贴)开始吧!

public int updatePublisherByTitle(Connection connection,String tableName, String title, String publisher){
//请在此处实现数据更新功能
Statement stmt = null;
int updatedNum=0;
String sqlScript = "update " + tableName + " set publisher=\'" + publisher + "\'where title=\'" + title + "\'";
try {
stmt = connection.createStatement();
updatedNum = stmt.executeUpdate(sqlScript);
} catch (SQLException e) {
e.printStackTrace();
}
return updatedNum;
}


运行截屏:

此图片的alt属性为空;文件名为882280298.png

关卡七

此图片的alt属性为空;文件名为4100481026.png

让我们愉快的(复制粘贴)开始吧!

//请在此处补全转换表的SQL语句,不要改动其他代码
/******* Begin ******/
ResultSet result = null;
Statement stmt = null;
String sqlScript = "select * from " + tableName + " order by id desc";
try {
stmt = connection.createStatement();
result = stmt.executeQuery(sqlScript);
} catch (SQLException e) {
e.printStackTrace();
}
String sqlInsert = "insert into transformedBook (id,column_name,value) values (";
while (result.next()) {
String sql = "";
String id = result.getString("id");
String title=result.getString("title");
if(title != null)
{
sql = sqlInsert + id + ",'" + "title" + "','" + title + "');";
InsertRecord(connection, sql);
}
String author = result.getString("author");
if(author != null)
{
sql = sqlInsert + id + ",'" + "author" + "','" + author + "');";
InsertRecord(connection, sql);
}
String publisher = result.getString("publisher");
if(publisher != null)
{
sql = sqlInsert + id + ",'" + "publisher" + "','" + publisher + "');";
InsertRecord(connection, sql);
}
String publishYear = result.getString("publishYear");
if(publishYear != null)
{
sql = sqlInsert + id + ",'" + "publishYear" + "','" + publishYear + "');";
InsertRecord(connection, sql);
}
}
/******* End ******/

运行截屏:

此图片的alt属性为空;文件名为3622001743.png

大功告成!
此图片的alt属性为空;文件名为passpart.cc679602.png
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!