这个文件怎么导入到数据库里?

awt_boy 2008-03-16 12:36:05
======================================================
Name: CVE-1999-0004
Status: Candidate
URL: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-1999-0004
Phase: Modified (19990621-01)
Category: SF
Reference: CERT:CA-98.10.mime_buffer_overflows
Reference: XF:outlook-long-name
Reference: SUN:00175
Reference: MS:MS98-008
Reference: URL:http://www.microsoft.com/technet/security/bulletin/ms98-008.asp

MIME buffer overflow in email clients, e.g. Solaris mailtool
and Outlook.


Current Votes:
ACCEPT(8) Magdych, Northcutt, Wall, Baker, Landfield, Cole, Dik, Collins
MODIFY(1) Frech
NOOP(1) Christey
REVIEWING(1) Shostack

Voter Comments:
Frech> Extremely minor, but I believe e-mail is the correct term. (If you reject
this suggestion, I will not be devastated.) :-)
Christey> This issue seems to have been rediscovered in
BUGTRAQ:20000515 Eudora Pro & Outlook Overflow - too long filenames again
http://marc.theaimsgroup.com/?l=bugtraq&m=95842482413076&w=2

Also see
BUGTRAQ:19990320 Eudora Attachment Buffer Overflow
http://marc.theaimsgroup.com/?l=bugtraq&m=92195396912110&w=2
Christey>
CVE-2000-0415 may be a later rediscovery of this problem
for Outlook.
Dik> Sun bug 4163471,
Christey> ADDREF BID:125
Christey> BUGTRAQ:19980730 Long Filenames & Lotus Products
URL:http://marc.theaimsgroup.com/?l=bugtraq&m=90221104526201&w=2


======================================================
Name: CVE-1999-0005
Status: Entry
Reference: CERT:CA-98.09.imapd
Reference: SUN:00177
Reference: URL:http://sunsolve.sun.com/pub-cgi/retrieve.pl?doctype=coll&doc=secbull/177
Reference: BID:130
Reference: URL:http://www.securityfocus.com/bid/130
Reference: XF:imap-authenticate-bo

Arbitrary command execution via IMAP buffer overflow in authenticate
command.
...全文
129 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bootupnow 2008-03-17
  • 打赏
  • 举报
回复
数据库是mssql 2000,楼主将就看看了,mysql的换换驱动应该一样。
bootupnow 2008-03-17
  • 打赏
  • 举报
回复
下面是代码:

import java.sql.*;

public class ConnectionFactory {
private static ConnectionFactory ref = new ConnectionFactory();
private static final String DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String URL_LOCAL = "jdbc:sqlserver://localhost:1433;DatabaseName=test";
private static final String USER_NAME = "test";
private static final String USER_PWD = "password";

private ConnectionFactory(){
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
}
}

public static Connection getConnection(int mode){
try{
switch(mode){
case 0:
return DriverManager.getConnection(URL_LOCAL,USER_NAME,USER_PWD);
case 1:
// todo
default:
return null;
}
}catch(SQLException sqle){
sqle.printStackTrace();
return null;
}
}

public static void close(ResultSet rst){
if(rst != null){
try{
rst.close();
}catch(SQLException sqle){
sqle.printStackTrace();
}
}
}

public static void close(Statement stmt){
if(stmt != null){
try{
stmt.close();
}catch(SQLException sqle){
sqle.printStackTrace();
}
}
}

public static void close(Connection conn){
if(conn != null){
try{
conn.close();
}catch(SQLException sqle){
sqle.printStackTrace();
}
}
}
}






import java.io.*;
import java.sql.*;

public class TransferItems {

// create table info(
// Name varchar(800),
// Status varchar(800),
// URL varchar(800),
// Phase varchar(800),
// Category varchar(800),
// Reference varchar(800),
// dis varchar(3000)
// )


private String name;
private String status;
private String url;
private String phase;
private String category;
private String reference;
private String dis;


/**
* 填充一下
*
* */
private void fill(String name,String status,String url,String phase,
String category,String reference,String dis){
this.name = name;
this.status = status;
this.url = url;
this.phase = phase;
this.category = category;
this.reference = reference;
this.dis = dis;

}

/**
* 清理一下
*
* */
private void clean(){
this.name = "";
this.status = "";
this.url = "";
this.phase = "";
this.category = "";
this.reference = "";
this.dis = "";

}

/**
* 从
*
* */
public void doSomething(String filePath){
File f = new File(filePath);
if (!f.isFile()){
System.out.println("文件不存在!");
return;
}
try{
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String tmpLine = ""; // 临时存放行内容
boolean isBeginFlag = true; // 标志 开始 ===================
while( ((tmpLine = br.readLine())) != null ){
if(!tmpLine.startsWith("=======================") && !"".equals(tmpLine) ){
String strPrefix = tmpLine.substring(0,tmpLine.indexOf(":")>=0?tmpLine.indexOf(":")+1:1);
// System.out.println(strPrefix);
if (strPrefix.compareToIgnoreCase("Name:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
name += tmpLine;
}
else if(strPrefix.compareToIgnoreCase("Status:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
status += tmpLine;
}
else if(strPrefix.compareToIgnoreCase("URL:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
url += tmpLine;
}
else if(strPrefix.compareToIgnoreCase("Phase:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
phase += tmpLine;
}
else if(strPrefix.compareToIgnoreCase("Category:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
category += tmpLine;
}
else if(strPrefix.compareToIgnoreCase("Reference:") == 0) {
tmpLine = tmpLine.substring(tmpLine.indexOf(strPrefix) + strPrefix.length());
reference += tmpLine;
}
else{
dis += tmpLine;
}
}
else if(tmpLine.startsWith("=======================")){
// tmpLine = "分隔符";
if(isBeginFlag){ // 如果是第一次的 ===================== 就跳过,以后遇到代表提交
isBeginFlag = false;
clean(); // 清理
continue;
}
fill(name,status,url,phase,category,reference,dis); // 准备
doInsert(); // 插入
clean(); // 清理

}
// 显示文件内容
System.out.println(tmpLine);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}
}


/**
* 插入
*
* */
private void doInsert(){
Connection conn = null;
PreparedStatement pstmt = null;
String strSQL = "INSERT INTO info VALUES(?,?,?,?,?,?,?)";
try {
conn = ConnectionFactory.getConnection(0);
pstmt = conn.prepareStatement(strSQL);
pstmt.setString(1, this.name);
pstmt.setString(2, this.status);
pstmt.setString(3, this.url);
pstmt.setString(4, this.phase);
pstmt.setString(5, this.category);
pstmt.setString(6, this.reference);
pstmt.setString(7, this.dis);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally{
ConnectionFactory.close(pstmt);
ConnectionFactory.close(conn);
}
}

public static void main(String[] args){
new TransferItems().doSomething("C:/a.txt");
}
}
bootupnow 2008-03-17
  • 打赏
  • 举报
回复

楼主发了n个帖子,sql版也是,哈哈。
偶写了一个很烂的,仅供参考了,希望达人能够补充。
http://topic.csdn.net/u/20080316/10/e79186a3-3e2f-4bb8-af81-0cef4ff15234.html



楼主的要求:去掉连等号,每行第一个冒号之前的为字段共7个字段:name,status,url,phase,
category,reference,dis.其中相同的referende为一个字段,没有表明字段的所有内容
(最后一个reference一下的内容)去掉多余的回车,全部都归到dis字段里

不知如何导入到mysql数据库中呢?或者大家可以帮我写个操作文本文件的程序也可以

实例文件:


======================================================
Name: CVE-1999-0004
Status: Candidate
URL: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-1999-0004
Phase: Modified (19990621-01)
Category: SF
Reference: CERT:CA-98.10.mime_buffer_overflows
Reference: XF:outlook-long-name
Reference: SUN:00175
Reference: MS:MS98-008
Reference: URL:http://www.microsoft.com/technet/security/bulletin/ms98-008.asp

MIME buffer overflow in email clients, e.g. Solaris mailtool
and Outlook.


Current Votes:
ACCEPT(8) Magdych, Northcutt, Wall, Baker, Landfield, Cole, Dik, Collins
MODIFY(1) Frech
NOOP(1) Christey
REVIEWING(1) Shostack

Voter Comments:
Frech> Extremely minor, but I believe e-mail is the correct term. (If you reject
this suggestion, I will not be devastated.) :-)
Christey> This issue seems to have been rediscovered in
BUGTRAQ:20000515 Eudora Pro & Outlook Overflow - too long filenames again
http://marc.theaimsgroup.com/?l=bugtraq&m=95842482413076&w=2

Also see
BUGTRAQ:19990320 Eudora Attachment Buffer Overflow
http://marc.theaimsgroup.com/?l=bugtraq&m=92195396912110&w=2
Christey>
CVE-2000-0415 may be a later rediscovery of this problem
for Outlook.
Dik> Sun bug 4163471,
Christey> ADDREF BID:125
Christey> BUGTRAQ:19980730 Long Filenames & Lotus Products
URL:http://marc.theaimsgroup.com/?l=bugtraq&m=90221104526201&w=2


======================================================
Name: CVE-1999-0005
Status: Entry
Reference: CERT:CA-98.09.imapd
Reference: SUN:00177
Reference: URL:http://sunsolve.sun.com/pub-cgi/retrieve.pl?doctype=coll&doc=secbull/177
Reference: BID:130
Reference: URL:http://www.securityfocus.com/bid/130
Reference: XF:imap-authenticate-bo

Arbitrary command execution via IMAP buffer overflow in authenticate
command.
======================================================
awt_boy 2008-03-16
  • 打赏
  • 举报
回复
你的答案对我毫无用处噢,应该付我钱吧
老紫竹 2008-03-16
  • 打赏
  • 举报
回复
我只能说这么多,你这问题如果你没思路,会耗费很长时间。

我提一个思路,剩下的自己弄
1 一那个等号作为分隔符,划分成不同的片断
2 在一个片断里,找到各个元素的标志,比如
Name
Status
URL
Voter Comments:

3 注意他们如果出现,则顺序是固定的

OK 我只能提供这么多了!自己加油!

如果在说,得付费了! 1000亿英镑吧!给你打95折
awt_boy 2008-03-16
  • 打赏
  • 举报
回复
这也叫规则?我不是要把所有的东西都导入到数据库里噢,连等号和回车这些怎么去掉?
还有,有些记录是有URL,STATUS,PHASE,但有些记录又没有这些字段,怎么导啊?
那个文本文件有18M那么大啊!
老紫竹 2008-03-16
  • 打赏
  • 举报
回复
不懂你的意思。

打开文件,读取全部内容到字符串
连接数据库
insert 就可以了!


你不是想格式化文本吧!
看你的文件格式挺规矩的,一行一行的自己解析啊!

老紫竹 2008-03-16
  • 打赏
  • 举报
回复
恩!有道理!你还是很聪明的! 搞定它!!呵呵!!

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧