お知らせNPC

Go down

お知らせNPC

投稿 by 構築さん on 2014-05-30, 09:28

SQLからお知らせの内容を読み込みNPCで表示させる。

NPCConversationManager.java


Code:
public String getNoticeList() {
String text = "";
PreparedStatement ps;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM notice ORDER BY id DESC LIMIT 8");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
text += "#L";
text += rs.getInt("id");
text += "#";
text += rs.getString("title");
text += "\t-\t";
text += rs.getString("data");
text += "#l\r\n";
}
rs.close();
ps.close();
} catch (Exception e) {
System.out.println("SQL読み込みエラ[ : getNoticeList");
}
return text;
}

public String getNotice(int id) {
String text = "";
PreparedStatement ps;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM notice WHERE id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
text += "#r#e";
text += rs.getString("title");
text += "#n#k\t-\t#d";
text += rs.getString("data");
text += "#k\r\n\r\n";
text += rs.getString("text");
}
rs.close();
ps.close();
} catch (Exception e) {
System.out.println("SQL読み込みエラ[ : getNotice");
}
return text;
}


Code:
CREATE TABLE `notice` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data` tinytext NOT NULL,
`title` tinytext NOT NULL,
`text` longtext NOT NULL,
PRIMARY KEY (`id`)
);


JS

Code:
var status = -1;
var text = "";
function action(mode, type, selection) {
if (mode == 1) {
status++;
} else {
cm.dispose();
return;
}
if (status == 0) {
text = cm.getNoticeList();
cm.sendSimple("お知らせ:\r\n" +text);
} else if (status == 1) {
cm.sendOk(cm.getNotice(selection));
cm.dispose();
}
}
avatar
構築さん
Admin

Posts : 193
Join date : 2014/05/29

http://maplescience.forumjap.com

トップに戻る Go down

トップに戻る


 
Permissions in this forum:
返信投稿: 不可