package spring;

import static org.junit.Assert.fail;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import org.junit.Test;

public class DBTest {

	@Test
	public void test() {
		fail("Not yet implemented");
	}
	
	/**
	 * 使用Driver连接数据库
	 * @throws SQLException
	 */
	@Test
	public void DriverTest() throws SQLException{
		
		Driver driver = new com.mysql.jdbc.Driver();
		
		String url = "jdbc:mysql://192.168.100.141:3306/Evolution?characterEncoding=utf8&useSSL=true";
		Properties info = new Properties();
		info.put("user", "root");
		info.put("password", "123");
		Connection connection = driver.connect(url, info);
		System.out.println(connection);
	}
	
	@Test
	/**
	 * 使用DriverManager连接数据库（可以管理多个连接）
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public void DriverManagerTest() throws ClassNotFoundException, SQLException{
		
		Class.forName("com.mysql.jdbc.Driver");
		
		String url = "jdbc:mysql://192.168.100.141:3306/Evolution?characterEncoding=utf8&useSSL=true";
		String user = "root";
		String password = "123";
		
		Connection connection = DriverManager.getConnection(url, user, password);
		System.out.println(connection);
		
	}

}

@@ -154,28 +154,120 @@
 ava.sql.
-SQLException
+PreparedStatement;%0D%0Aimport java.sql.ResultSet;%0D%0Aimport java.sql.SQLException;%0D%0Aimport java.sql.Statement
 ;%0D%0Aimpor
@@ -866,24 +866,47 @@
 nnection);%0D%0A
+%09%09connection.close();%0D%0A
 %09%7D%0D%0A%09%0D%0A%09@Tes
@@ -1386,43 +1386,880 @@
 %0D%0A%09%09
-System.out.println(connection);%0D%0A%09%09
+%0D%0A%09%09/*//%E6%9B%B4%E6%96%B0id%E4%B8%BA123%E7%9A%84%E6%95%B0%E6%8D%AE%0D%0A%09%09String sql = %22update T_Sys_Log set user_name= ? where id='123' %22;%0D%0A%09%09PreparedStatement pStatement = connection.prepareStatement(sql);%0D%0A%09%09pStatement.setString(1, %22%E5%B0%8F%E6%9E%97%22);%0D%0A%09%09int i = pStatement.executeUpdate();%0D%0A%09%09System.out.println(%22%E6%9B%B4%E6%96%B0%E6%9D%A1%E6%95%B0%EF%BC%9A%22+i);*/%0D%0A%09%09%0D%0A%09%09%0D%0A%09%09String sql = %22select * from T_Sys_Log%22;%0D%0A%09%09PreparedStatement pStatement = connection.prepareStatement(sql);%0D%0A%09%09ResultSet resultSet = pStatement.executeQuery();%0D%0A%09%09while(resultSet.next())%7B%0D%0A%09%09%09System.out.println(resultSet.getString(1));%0D%0A%09%09%09System.out.println(resultSet.getString(2));%0D%0A%09%09%09System.out.println(resultSet.getString(3));%0D%0A%09%09%09System.out.println(resultSet.getString(4));%0D%0A%09%09%09System.out.println(resultSet.getString(5));%0D%0A%09%09%09System.out.println(%22--------------------------------%22);%0D%0A%09%09%7D%0D%0A%09%09resultSet.close();%0D%0A%09%09System.out.println(connection);%0D%0A%09%09pStatement.close();%0D%0A%09%09connection.close();
 %0D%0A%09%7D

add test