public static String url = "jdbc:mysql://ip/database?characterEncoding=UTF-8";  //在database 后面加上?characterEncoding=UTF-8 就可以解决java 插入数据中文乱码问题
public static String username = "user";
public static String password = "123";
public static Connection conn;
public static Statement stmt;
public static ResultSet rs;
public static DataStructure ds = new DataStructure(); /*public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} try {
conn = DriverManager
.getConnection("jdbc:mysql://ip/databases?user=user&password=pass&useUnicode=true&characterEncoding=utf-8");
conn = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return conn; }*/ public void closeConnection(Connection conn) { if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*
// 实现查询操作
public static void select(String sql) {
try {
rs = stmt.executeQuery(sql);
ResultSetMetaData meta_data = rs.getMetaData();// 列名
for (int i_col = 1; i_col <= meta_data.getColumnCount(); i_col++) {
System.out.print(meta_data.getColumnLabel(i_col) + " ");
}
System.out.println();
while (rs.next()) {
for (int i_col = 1; i_col <= meta_data.getColumnCount(); i_col++) {
System.out.print(rs.getString(i_col) + " ");
}
System.out.println();
}
rs.close();
} catch (Exception e) {
System.out.println("数据查询失败!");
}
}*/ public static void insertd(String sql) {
try {
conn = DriverManager.getConnection(url, username, password);
conn.setAutoCommit(false);
stmt = conn.prepareStatement("load data local infile '' "
+ "into table loadtest fields terminated by ','");
StringBuilder sb = new StringBuilder();
InputStream is = new ByteArrayInputStream(sb.toString().getBytes());
((com.mysql.jdbc.Statement) stmt).setLocalInfileInputStream(is);
stmt.executeUpdate(sql);
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
String sql = ("insert into bns_user (userurl, titleurl, createtime, username, titleabout ) values ('12','1','1','1','1')");
insertd(sql); }

最新文章

  1. Web Modify The Html Elements According Url Parameters With Jquery
  2. SaveData Functions
  3. CODESOFT中怎样打印数据库中的特定数据?
  4. C++临时变量的生命周期
  5. android开发 wifi开发工具类
  6. Asp.net弹出层并且有遮罩层
  7. this class is not key value coding-compliant for the key ##
  8. Android开发之自定义组合控件
  9. C# 接口的隐式与显示实现【转】
  10. ETL构建数据仓库五步法
  11. linux考试基础知识测验
  12. flexbox弹性盒子模型
  13. Haxe UI框架StablexUI的使用备忘与心得(一)
  14. Dockerfile详解
  15. sass入门学习篇(一)
  16. threading多线程总结
  17. 深入理解PHP的运行模式
  18. Ubuntu软件安装与卸载
  19. leetcode1:两数之和
  20. Ubantu常用命令

热门文章

  1. php获取网页源码分行显示
  2. ajax请求是的动画实现
  3. 使用poi实现生成excel文件
  4. HTTP与HTTPS的区别与联系
  5. 十、 shell基础
  6. 如果在vue中实现一个输入框的抖动效果?
  7. Xcode使用篇-重新安装Xcode
  8. 10.Struts2值栈
  9. 单向连通图 Going from u to v or from v to u? poj2762
  10. SSM基本配置