一、jsp連線oracle8/8i/9i資料庫(用thin模式)
testoracle.jsp如下:
<%class.forname("oracle.jdbc.driver.oracledriver").newinstance();
string url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl為你的資料庫的sid
string user="scott";
string password="tiger";
connection conn= drivermanager.getconnection(url,user,password);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
二、jsp連線sql server7.0/2000資料庫
testsqlserver.jsp如下:
<%class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver").newinstance();
string url="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
//pubs為你的資料庫的
string user="sa";
string password="";
connection conn= drivermanager.getconnection(url,user,password);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
三、jsp連線db2資料庫
testdb2.jsp如下:
string url="jdbc:db2://localhost:5000/sample";
//sample為你的資料庫名
string user="admin";
string password="";
connection conn= drivermanager.getconnection(url,user,password);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
四、jsp連線informix資料庫
testinformix.jsp如下:
<%class.forname("com.informix.jdbc.ifxdriver").newinstance();
string url =
"jdbc:informix-sqli://123.45.67.89:1533/testdb:informixserver=myserver;
user=testuser;password=testpassword";
//testdb為你的資料庫名
connection conn= drivermanager.getconnection(url);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
五、jsp連線sybase資料庫
testmysql.jsp如下:
<%class.forname("com.sybase.jdbc.sybdriver").newinstance();
string url =" jdbc:sybase:tds:localhost:5007/tsdata";
//tsdata為你的資料庫名
properties sysprops = system.getproperties();
sysprops.put("user","userid");
sysprops.put("password","user_password");
connection conn= drivermanager.getconnection(url, sysprops);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
六、jsp連線mysql資料庫
testmysql.jsp如下:
<%class.forname("org.gjt.mm.mysql.driver").newinstance();
string url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useunicode=true&characterencoding=8859_1"
//testdb為你的資料庫名
connection conn= drivermanager.getconnection(url);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
七、jsp連線postgresql資料庫
testmysql.jsp如下:
<%class.forname("org.postgresql.driver").newinstance();
string url ="jdbc:postgresql://localhost/soft"
//soft為你的資料庫名
string user="myuser";
string password="mypassword";
connection conn= drivermanager.getconnection(url,user,password);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql="select * from test";
resultset rs=stmt.executequery(sql);
while(rs.next()) %>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
jsp連線資料庫大全
create table test test1 varchar 20 test2 varchar 20 一 jsp連線oracle8 8i 9i資料庫 用thin模式 orcl為你的資料庫的sid pubs為你的資料庫的 三 jsp連線db2資料庫 sample為你的資料庫名 testdb為你的資料...
jsp連線資料庫大全
現在有好多初學jsp sun企業級應用的首選 的經常會問資料庫怎麼連線啊,怎麼老出錯啊?所以我集中的在這寫篇文章供大家參考,其實這種把資料庫邏輯全部放在jsp sun企業級應用的首選 裡未必是好的做法,但是有利於初學者學習,所以我就這樣做了,當大家學到一定程度的時候,可以考慮用mvc的模式開發。在練...
JSP連線資料庫方法大全
一 jsp連線oracle8 8i 9i資料庫 用thin模式 testoracle.jsp如下 string url jdbc oracle thin localhost 1521 orcl orcl為你的資料庫的sid string user scott string password tige...
連線資料庫大全
oracle8 8i 9i資料庫 用thin模式 testoracle.jsp如下 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl or...
jsp連線資料庫oracle
create table test test1 varchar 20 test2 varchar 20 然後向這個表寫入一條測試紀錄 那麼現在開始我們的jsp sun企業級應用的首選 和資料庫之旅吧。testoracle 大型 資料庫平臺 jsp sun企業級應用的首選 如下 大型 資料庫平臺 jd...