欢迎光临
我们一直在努力

CONNECTING DATABASE USING JAVASERVERPAGES (转载)-JSP教程,Jsp/Servlet

建站超值云服务器,限时71元/月

i have given you the source code, how to connect with database from jsp. this is easy and simple.cut and paste the below code and modify according to your requirements.this is esspecially for those who had coding experience in asp.i have given proper documentation.  

<!–first weve to import the necessary packages–>
<!–importing packages starts–>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<!–importing packages ends–>
<%
try
{
//loading the drivers
//this code loads jdbd-odbc driver
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
//making connection
//the second step in establishing a connection is to have the appropriate
//driver connect to the dbms. the following line of code illustrates the
//general idea:
string url="jdbc:odbc:test";
//where "test" is the system dsn name
connection con=drivermanager.getconnection(url, "administrator", "password");
//where "administrator is the username to
//access the database and password is " password"
//drivermanagers getconnection method estabilishes connection
//with the database specified in the jdbc url
//then create jdbc statement
statement stmt = con.createstatement();
string query="create table coffees" +
"(cof_name varchar(32),"+
"sup_id integer,"+
"price float,"+
"sales integer,"+
"total integer)";
//execute the statement
stmt.executeupdate(query);
}
catch (exception e) {}
//give confirmation message
out.println("table coffees created");
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » CONNECTING DATABASE USING JAVASERVERPAGES (转载)-JSP教程,Jsp/Servlet
分享到: 更多 (0)

相关推荐

  • 暂无文章