假設(shè)登陸Oracle的數(shù)據(jù)庫(kù),連接方式
我們提供的服務(wù)有:網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、雁塔ssl等。為超過(guò)千家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的雁塔網(wǎng)站制作公司
String driver = "oracle.jdbc.OracleDriver";
Connection cn = null;
Class.forName(driver);
String url = "jdbc:oracle:thin:@localhost:1521:ORACLE";
String user = "system";
String pwd = "密碼";
cn = DriverManager.getConnection(url,user,pwd);
Statement st = cn.createStatement();
String sql = "Insert into loginfo (id,username,user,type) values( "id="+你的id+"username="+user+",password="+pwd+",type="+你的type);
st.executeUpdate(sql);
st.closed;
cn.closed;
Mysql Database
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/數(shù)據(jù)庫(kù)名稱",
"賬戶","密碼");
localhost你的ip地址
3306 mysql的數(shù)據(jù)庫(kù)端口號(hào)這個(gè)不用改
package cc.icoc.javaxu.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class MySQLOprea { /** * 增加記錄 INSERT INTO 表名(字段名,字段名) VALUES (值,值); * 刪除記錄 DELETE FROM 表名 WHERE 條件() * 修改記錄 UPDATE 表名 SET 字段=值,字段=值 WHERE 條件 * 查詢記錄 SELECT 字段,字段 FROM 表名 WHERE 條件 */ ResultSet rs = null; Connection conn = null; Statement statement = null; //鏈接 public Connection connSQL() { String DRIVER = "com.mysql.jdbc.Driver";// 數(shù)據(jù)庫(kù)驅(qū)動(dòng) String URL = "jdbc:mysql://localhost:3306/mydata?useUnicode=truecharacterEncoding=gb2312";// String DBNAME = "root";// 用戶名 String DBPASS = "341341";// 密碼 try { Class.forName(DRIVER).newInstance();// 注冊(cè)驅(qū)動(dòng) conn = DriverManager.getConnection(URL, DBNAME, DBPASS); statement = conn.createStatement(); } catch (Exception e) {} return conn; } //增 /** * 插入新記錄的操作 * @param table 表名 * @param userName 插入的用戶名 * @param passWord 插入的用戶密碼 * @return true代表插入成功,false代表插入失敗 */ public String insert(String table, String userName, String passWord) { connSQL(); String s = "注冊(cè)成功"; try { String insert = "insert into "+table+"(userName,passWord) values ("+"'"+userName+"'"+","+"'"+passWord+"'"+")"; statement.executeUpdate(insert); closeDB(); } catch (Exception e) { // TODO: handle exception s = "注冊(cè)失敗"+e.toString(); } return s; } //刪 public void delete(String table, String whereValue) throws SQLException { String delete = "Delete from "+table+" where userName = "+whereValue; statement.executeUpdate(delete); } //改 public void update(String table, String whereValue , String newValue) throws SQLException { String update = "Update "+table+" set passWord ="+newValue+" where userName ="+whereValue; statement.executeUpdate(update); } //查 public String query(String table , String whereValue1 ,String whereValue2, String whatCol1, String whatCol2) throws SQLException { connSQL(); String query = null;// ResultSet set= null; try { query = "select "+whatCol1+","+whatCol2+" from "+table +" where "+whatCol1+"="+'"'+whereValue1+'"'+" and "+whatCol2+"="+'"'+whereValue2+'"'; rs = statement.executeQuery(query); closeDB(); } catch (Exception e) { // TODO: handle exception return "false exception:"+e.toString(); } if(rs.next()) { return "true:"; } return "false:"; } private void closeDB() { // TODO Auto-generated method stub try { if(rs != null) { rs.close(); } if(statement != null) { statement.close(); } if(conn != null) { conn.close(); } } catch (Exception e) { // TODO: handle exception System.out.println("數(shù)據(jù)庫(kù)關(guān)閉時(shí)出現(xiàn)異常"); } }}
跑這兒作家庭作業(yè)了? 如果連用哪種頁(yè)面技術(shù)都不知道提的話,恐怕別人給你源代碼你也看不懂哦,想想別人給你個(gè)tapestry、Wicket之類的寫的代碼,拿給老師肯定挨批的喲(一看就露餡了)。
你這個(gè)不用數(shù)據(jù)庫(kù)真的是有點(diǎn)難搞
我寫了個(gè)用集合存儲(chǔ)的,你看看,能否幫上你
java.util.ListString?list?=?new?ArrayListString();
list.add("qq=123");//存儲(chǔ)的時(shí)候用(用戶名=密碼)的形式
list.add("ww=456");
String?username?=?"qq";
String?password?=?"123";
for?(int?i?=?0;?i??list.size();?i++)?{
String?num?=?username?+"="+password;
if(num.equals(list.get(i))){
System.out.println("登錄成功");
break;
}
}
Java寫提示注冊(cè)成功的方法如下:
1、首先用戶注冊(cè)完成后,返回一個(gè)boolean值的變量;
2、利用Servlet類判斷這個(gè)變量,如果為true,跳轉(zhuǎn)到提示界面,提示用戶注冊(cè)成功,如果為false,跳轉(zhuǎn)到提示界面,提示用戶注冊(cè)失??;
3、具體代碼如下所示:
public?class?DemoServlet?extends?HttpServlet?{
public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?{
String?username?=?request.getParameter("username");
String?usepwd=?request.getParameter("usepwd");
boolean?flag?=?Dao.register(username,usepwd);//注冊(cè)方法
if(flag){
//提示注冊(cè)成功
request.getRequestDispatcher("/success.jsp").forward(request,?response);
}else{
//提示注冊(cè)失敗
request.getRequestDispatcher("/success.jsp").forward(request,?response);
}
}
public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?{
doGet(request,?response);
}
}
4、至此,就完成了提示注冊(cè)成功的功能。
你說(shuō)的java源代碼是指編譯成的class文件前的java文件。
當(dāng)我們運(yùn)行.java文件時(shí),它會(huì)被系統(tǒng)編譯成.class文件,例如Test.java編譯之后就是Test.class,
源文件就是指Test.java文件,
一般部署項(xiàng)目時(shí),有.class文件就可以發(fā)布運(yùn)行了,但是如果想修改這個(gè)系統(tǒng),.class是不能修改的,要有.java文件才能修改
也可以上網(wǎng)去下反編譯軟件,就是能把.class文件大部分還原成.java文件的工具,但不是100%還原,而且如果不是正版的,小心有毒啊,什么的。