最近需要做一个验证“ANDROID终端”下载数据的效率问题,其中需要到向sqlserver2008数据库中添加测试数据
step1:定义相关数据库信息
static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; static final String URL = "jdbc:sqlserver://192.168.0.249\\sql2008;databaseName=LZrfid"; static final String USER = "sa"; static final String PWD ="1" ;
step2:获取sql连接
/** * * 获取sql连接 * @return * @author * @since 1.0.0 */ public static Connection getConnection() { Connection con = null; try { Class.forName(DRIVER); con = DriverManager.getConnection(URL, USER,PWD); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return con; }
step3:简单的操作数据库
Statement statement; Connection connection; connection = getConnection(); statement = connection.createStatement(); String sql = "select * from ...."; statement.execute(sql);
以上只是最简单的连接操作,在此留存,便于自己以后查阅
时间: 2024-11-01 11:20:58