jsp連接數據庫的規範總結

1,從前一個頁面獲取參數後:

 

String name=request.getParameter("name");
if(name==null)
{ name=""; }

name 是上個界面傳遞的參數,如果沒有數值,則賦值爲空

 

2,解決中文問題

byte b[]=name.getBytes("ISO-8859-1");
name=new String(b);

建立b數組,重新用編碼編寫一下

 

3,數據庫代碼

 

Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e){}
try
{

con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","WJZwjz1029");
sql=con.createStatement();
rs=sql.executeQuery("select * from emp");

……

 

}

catch(SQLException e1) {out.print(""+e1);}
finally

{

con.close

}

發佈了24 篇原創文章 · 獲贊 11 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章