数据库连接
以MYSQL为例!
class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql//localhost:3306/DateName",
"userName","password");
class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql//localhost:3306/DateName",
"userName","password");
Statement stmt=conn.createStatment();
ResultSet rs=stmt.executeQuery("SQL语句");
while(rs.next())
{
rs.getString("列名");
rs.getString(2);
}
ResultSetMetaData rsmd=Statement.executeQuery("");
rsmd.getColumnCount();// 列数
rsmd.getColumnName(1).trim();//得到第一列的列名
//更新数据库
Result.next();
ResultSet.updateInt("列名",value);//对同一列的所有数据进行修改
ResultSet.updateRow();//更新数据库
//另外两个statement方式
PreparedStatement=Connection.prepareStatement(sql);
CallableStatement=Connection.prepareCall("{call 存储过程名(?,?)}");