實現註冊/登陸的基礎代碼
阿新 • • 發佈:2017-07-11
lose generate urn getc for ora update manager sem
package conn; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Conn { /** * 連接數據庫 * * @author Administrator * */ public Connection getConnection() { Connection conn= null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1522:xe", "smn", "orcl"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } /** * 添加數據 * @param conn * @param sql * @return 返回成功添加記錄數 */ public int updateMethord(Connection conn,String sql){int count=0; Statement st; try { st = conn.createStatement(); count=st.executeUpdate(sql); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return count; } public ResultSet selectMethord(Connection conn,String sql){ ResultSet rs=null; Statement st; try { st = conn.createStatement(); rs=st.executeQuery(sql); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rs; } public void closeMethord(Connection conn){ if(conn!=null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
實現註冊/登陸的基礎代碼