package com.rename;
import java.awt.Font;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.rename.Front;
public class SQL_Connect {
private String sql_url="jdbc:mysql://localhost:3306/newimage";
private String sql_user="root";
private String sql_psw="";
private Connection con;
private Statement stmt;
private String str[];
private String res[][];
private int clo=0;
SQL_Connect(){
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e1){
System.out.println("Sorry,can't find the Driver!");
}
try {
con = DriverManager.getConnection(sql_url,sql_user,sql_psw);
stmt = con.createStatement();
System.out.println("Find the Driver!");
} catch (SQLException e) {
e.printStackTrace();
}
}
public boolean insertNewImage() {
ResultSet rs;
String pname,c1,c2,c3,jpg,price,no,color;
String sql;
jpg=Front.img_nname+".jpg";
//c1 c2 c3 pname
price=Front.price;
nnoo=Front.nnoo;
pname=Front.img_oname;
c1=Front.c1;
c2=Front.c2;
c3=Front.c3;
color=Front.img_color;
sql = "insert into p(pname,c1,c2,c3,jpg,price,no,color) values (\'"+
pname+"\',\'"+c1+"\',\'"+c2+"\',\'"+c3+"\',\'"+jpg+"\',\'"+price+"\',\'"+nnoo+"\',\'"+color+"\')";
try {
stmt.executeUpdate(sql);
return true;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public String[][] get_c123(){
ResultSet rs;
String sql;
int col=0;
res=new String[500][5];
sql="select c1,c2,c3,oname,price from category order by c1,c2,c3";
try {
rs = stmt.executeQuery(sql);
while (rs.next()){
res[col][0] = rs.getString(1);
res[col][1] = rs.getString(2);
res[col][2] = rs.getString(3);
res[col][3] = rs.getString(4);
res[col][4] = rs.getString(5);
col++;
System.out.println(col);
}
Front.col=col;
return res;
} catch (SQLException e) {
System.out.println("error!");
e.printStackTrace();
}
System.out.println("null!");
return null;
}
public void close(){
try {
con.close();
stmt.close();
System.out.println("Close Connection!");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
最近正在忙着准备考研,抽空更新一下博客,学无止境,不能荒废了我陈独秀的一波波操作。
该项目主要用于淘宝类电商的产品资源生成存储和整合。
思路来源:http://www.bazhuayu.com 八爪鱼采集器 很不错的一个采集神器,不过他是由用户定义规则来爬取资源,会上网就能采集,无需懂技术。 还有一款是 火车头采集器,在平时的采集工作也经常用到。
主要环境:Java Mysql
主要工具 :Eclipse Navicat
初始化窗口:
import java.awt.EventQueue;
public class Main {
//源路径: E:\zoom\
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Front window = new Front();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}