Need to use the Sqljdbc.jar package
JSP code
1 <%@ Page Language="Java"Import="java.sql.*"Import="java.io.*"Import="java.util.*"pageencoding="Utf-8"%>2 <%3 StringPath=Request.getcontextpath ();4 StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";5 %>6 7 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en">8 <HTML>9 <Head>Ten <Basehref= "<%=basePath%>"> One A <title></title> - <Metahttp-equiv= "Pragma"content= "No-cache"> - <Metahttp-equiv= "Cache-control"content= "No-cache"> the <Metahttp-equiv= "Expires"content= "0"> - <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3"> - <Metahttp-equiv= "description"content= "This is my page"> - </Head> + <% - + Statement SQL; A ResultSet rs; at Stringdrivername= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; //loading the JDBC driver - StringDburl= "jdbc:sqlserver://172.16.0.5:1433; Databasename=web"; //connecting servers and databases - StringUserName= "SA"; //User name - Stringuserpwd= "htwy*99"; //Password - Connection Dbconn; - in try { - Class.forName (drivername); to Dbconn=drivermanager.getconnection (Dburl, UserName, userpwd); + SQL=dbconn.createstatement (); - RS=Sql.executequery ("select*from dbo. Staffbill"); the System.out.println ("Connection successful!"); //If the connection succeeds console output connection successful! * $ Out.println ("EmployeeID");Panax Notoginseng - the while(Rs.next ()) + { A the Out.println ("<br/>"); + out.println (rs.getstring (1)); - $ } $ - dbconn.close (); - } catch (Exception e) { the E.printstacktrace (); - } Wuyi %> the </Body> - </HTML>
Java Link SQL Server database