首页 > 数据库技术 > 详细

几行代码入门JDBC

时间:2014-04-16 15:12:03      阅读:568      评论:0      收藏:0      [点我收藏+]

本着实用性的原创,去除JDBC一些深入的东西。只是为了一个很好复习和或者入门,一个总结。

public class TestJDBC {
	
	private static Connection connection = null;
	
	
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		
		connection = getConnection();
		Statement statement = connection.createStatement();
		//建表
		//statement.execute("create table mytable(id integer,name varchar(20),password varchar(20))");
		//插入数据
		//statement.execute("insert into mytable values(1,‘name‘,‘name‘)");
		//更新
		//statement.execute("update mytable set name=‘lll‘ where id=1");
		//查询表内容
		/*
		ResultSet set = statement.executeQuery("select * from mytable");
		ResultSetMetaData meta = set.getMetaData();
		
		while(set.next()){
			for(int i=1;i<=meta.getColumnCount();i++){
				Object o = set.getString(i);
				System.out.print(o+" ");
			}
			System.out.println();
		}*/
		//删除
		//statement.execute("delete from mytable where id=1");
		//删除表
		//statement.execute("drop table mytable");
		
		statement.close();
		connection.close();
		
	}
	
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver");
		return DriverManager.getConnection("jdbc:mysql://localhost:3306/Test","root","");
	}

}


几行代码入门JDBC,布布扣,bubuko.com

几行代码入门JDBC

原文:http://blog.csdn.net/suifengerbi/article/details/23781641

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!