<% /* ***** JSQLConnect Examples ****** Overview -------- This sample JSP demonstrates using JSQLConnect to create and populate a table then fetch and display the data to the web browser. Database connections are aquired through the JDBC driver manager. Steps ----- 1. Load the JSQLConnect JDBC Driver. 2. Make a JDBC connection using the JDBC Driver Manager. 3. Create and populate a table 4. Display the rows from the table 5. Close the connection Requires -------- 1. Microsoft SQL Server is up and running. 2. The datasource, user and password in jdbc:JSQLConnect://localhost/database=master/user=sa/password=secret are valid 3. JSQLConnect.jar is in the classpath of your JSP/servlet engine. For example, if you are using Apache Tomcat 4.x JSQLConnect.jar should be in %CATALINA_HOME%\common\lib If you are using another servlet engine please consult that product's documentation regarding deployment of 3rd party libraries. 4. Your JSP/servlet engine and web server are running. Run the JSP ------------- There is no need to compile a JSP. Deploy the JSP. If you are using Tomcat 4.x :- Copy ExampleJSP.jsp to %CATALINA_HOME%/webapps/examples/jsp The specific URL to run the example depends on the servlet engine you are using. If you are using Tomcat 4.x run the example at a web browser with:- http://localhost:8080/examples/jsp/ExampleJSP.jsp The results of the result query will be displayed. */ %> <%@ page language="java" import="java.sql.*" %>

JSQLConnect JSP Example

<% String connectionURL; connectionURL = "jdbc:JSQLConnect://mssql6.mediawebperu.net/databaseName=mwebsit_kourier/user=mwebsit_kourier/password=megatrade"; out.println("DriverClass:com.jnetdirect.jsql.JSQLDriver
"); out.println("URL:"+connectionURL+"
"); out.println("
Table rows display:-
"); %> <% // Load the driver. Ensure JSQLConnect.jar is deployed into the servet engine's classpath. // You will need to restart the servlet engine after deploying the driver JAR to the classpath. Class.forName("com.jnetdirect.jsql.JSQLDriver"); // Make the DBMS connection Connection connection = DriverManager.getConnection(connectionURL); // Make the statement Statement statement = connection.createStatement(); // Generate query String Query = "SELECT * FROM AAL_EMPRESAS"; // Get the result and display it ResultSet queryResult = statement.executeQuery(Query); while(queryResult.next()) { out.println(""); } // Close the connection queryResult.close(); statement.close(); connection.close(); %>
Column 1 Column 2
"+queryResult.getString(1)+""+queryResult.getString(2)+"