java--数据库链接

package sql;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Statement;

public class test_1 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Connection conn =null;
	java.sql.Statement st =null;
	ResultSet rs =null;
	try {
		//注册驱动
		DriverManager.registerDriver(new com.mysql.jdbc.Driver());
		//建立连接
		 conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.1.1/test?useSSL=false", "root", "test");
		//创建Statement
		 st =conn.createStatement();
		//执行查询,得到结果集
		String sql="SELECT ip FROM oa_login WHERE login_time=‘2017-10-27 21:25:02‘";
		 rs = st.executeQuery(sql);
		while(rs.next()) {
			String ip =rs.getString("ip");
		 
			System.out.println(ip);
		 }
		/*
		 * while(rs.next()){ int id =rs.getInt("id"); String name =rs.getString("name");
		 * int age= rs.getInt("age");
		 * 
		 * }
		 */
		
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}finally {
		
		try {
			rs.close();
			st.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}

}

java--数据库链接

上一篇:read by other session导致oracle性能低


下一篇:read by other session导致oracle性能低