package com.b3log.src;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Submit {
/**
* driver mysql驱动 (不用修改)
* url MySQL数据库地址 (修改成你自己的MySQL地址)
* dbUser MySQL用户名 (修改成你自己的MySQL用户名)
* dbPwd MySQL密码 (修改成你自己的MySQL密码)
* sql 查询语句(不用修改)
* website 你自己的网站地址 (修改成你自己的网址)
* baiduUrl 往百度提交连接的地址,需要自己去百度弄
* http://zhanzhang.baidu.com/linksubmit/index
*
* 这个Java文件运行需要MySQL驱动jar包,方法如下:
* http://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html
*
*/
public static final String driver="com.mysql.jdbc.Driver";
public static final String url="jdbc:mysql://localhost:3306/raa4yz848k444l34?useUnicode=yes&characterEncoding=UTF-8";//直接复制博客程序中的jdbc内容即可
public static final String dbUser="root";
public static final String dbPwd="root";
public static final String sql = "select articlePermalink from b3_solo_article";
public static final String website = "jingxuetao.com";
public static final String baiduUrl = "http://data.zz.baidu.com/urls?site=jingxuetao.com&token=TrMsdfNmjoCdDFMj";
public static String getUrls() throws Exception{
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,dbUser,dbPwd);
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
StringBuffer sb = new StringBuffer();
while(rs.next()){
sb.append(website+rs.getString("articlePermalink")+"\n");
}
if(conn != null){
conn.close();
}
return sb.toString();
}
public static void main(String[] args) {
try {
URL url = new URL(baiduUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "curl/7.12.1 ");
conn.setRequestProperty("Content-Type", "text/plain");
conn.setRequestProperty("Content-Length", "83");
conn.connect();
OutputStream out = conn.getOutputStream();
String urls = getUrls();
System.out.println(urls);
out.write(urls.getBytes());
out.flush();
int responseCode = conn.getResponseCode();
if(responseCode == 200){
System.out.println("提交成功。。。。。。");
}else{
System.out.println("提交失败。。。。");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
有什么不懂的请留言
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于