几行代码入门JDBC

本着实用性的原创,去除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

上一篇:WPF 仪表盘 刻度盘 动态 加载中 开源


下一篇:SQL 注入学习(来自freebuf的总结)