码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库__Jdbc直接操作__PreparedStatement__新增数据表

时间:2017-10-08 12:58:26      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:word   char   red   highlight   har   ros   block   trace   int   

一、代码如下

private void cTable() {
		// TODO Auto-generated method stub
		java.sql.PreparedStatement ps = null;
		java.sql.Connection cn = null;
		ResultSet rs = null;

		try {
			// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			cn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/learn?user=root&password=&useUnicode=true&characterEncoding=UTF8");
			ps = cn.prepareStatement("create table xxxx(aa int)");

			
			int i= ps.executeUpdate();
			System.out.println(i);
			if(i>=1) {
				System.out.println("数据表新增:成功");
			}else {
				System.out.println("数据表新增:失败");				
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				ps.close();
				cn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

 

mysql数据库__Jdbc直接操作__PreparedStatement__新增数据表

标签:word   char   red   highlight   har   ros   block   trace   int   

原文地址:http://www.cnblogs.com/wujianbo123/p/7637041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!