The full name of JSP is Java Server Pages, and the Chinese name is java server page. It is basically a simplified Servlet design. It was initiated by Sun Microsystems and established with the participation of many companies. A dynamic web technology standard.
JSP technology is somewhat similar to ASP technology. It inserts Java program segments (Scriptlet) and JSP tags into traditional web page HTML (a subset of standard universal markup language) files (*.htm, *.html) (tag), thus forming a JSP file with the suffix (*.jsp). Web applications developed with JSP are cross-platform and can run under Linux as well as other operating systems.
The method for jsp to connect to sql database is as follows:
Connection 参数//这个参数用来执行链接数据库的操作 String 参数2="com.microsoft.sqlserver.jdbc.SQLServerDriver";//双引号里的是MicroSoft 的 SQL Server 数据库驱动,它可以帮助你连接到 SQL Server 数据库,这样,应用程序才可以编写 SQL 语句以获得、更改或新增数据 String 参数3="jdbc:sqlserver://localhost:1433;DatabaseName=数据库名";//连接字符串,格式: "jdbc:公司名称:数据库驱动名称://数据库服务器ip:端口号;DatabaseName=数据库名称" String 参数4="sa";//数据库的总入口,一般是sa String 参数5="密码";//有你设置的密码 try{ Class.forName(参数2);//加载完驱动类,开始执行静态初始化代码时,会自动新建一个Driver的对象,并调用DriverManager.registerDriver把自己注册到DriverManager中去。 参数 = DriverManager.getConnection(参数3,参数4,参数5);//很关键的一部,向数据库请求 } catch(Exception e) { e.printStackTrace();//此处也可以确定是否连接上数据库,如果连接失败会报错。 }
The above is the detailed content of How to connect jsp to sql database?. For more information, please follow other related articles on the PHP Chinese website!