userdbopreation.java

来自「JSP初学者」· Java 代码 · 共 40 行

JAVA
40
字号
package xinwen;import java.sql.*;public class UserDbOpreation {    Connection dbConnection = null;	PreparedStatement pStatement = null;	ResultSet res = null;	public int UsersInsert(User name) throws SQLException	{		int result = 0;		try		{			dbConnection = ConnectionManager.getConnection();			String sqlStr = "insert into User (loginname,password) values(?,?)";			pStatement = dbConnection.prepareStatement(sqlStr);			pStatement.setString(1, name.getName());			pStatement.setString(2, name.getPassWord());			pStatement.executeUpdate();			sqlStr = "select count(*) from User ";			pStatement = dbConnection.prepareStatement(sqlStr);			res = pStatement.executeQuery();		}		catch (Exception e)		{			e.printStackTrace();		}		finally		{			ConnectionManager.closeResultSet(res);			ConnectionManager.closeStatement(pStatement);			ConnectionManager.closeConnection(dbConnection);		}		return result;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?