ODBC connection with phpmyadmin + Xampp Server




Dear friends,



First of all, you must Install Xampp Server >=3.2.2 in your local machine and you should start Apache, Mysql and Tomcat as shown above the screen.



Our Goal: Display a simple list of data from myself, using  PHPMyAdmin(Xampp server)  and JSP ODBC Connection jar file.



Tomcat: Tomcat nomenclature have the same structure in Xampp server also but few things you must keep in mind java.policy and valid connector jar file in lib folder according to xampp version.



Location : xampp\tomcat\webapps\user\WEB-INF\lib\connection.jar files

xampp\tomcat\webapps\foldername\ list.jsp file



Challenges: If you are facing the port or permission issue while connecting PHPMyAdmin with odbc.  You must look into the policy. java file in your java 's lib folder.This is a very prominent file. anything would you like to change, Please take the backup first.


Path :install_root/java/jre/lib/security/java.policy 


Updated Policy File: You can try until and unless you get permission issue or port issue in xampp server .


// Standard extensions get all permissions by default



grant codeBase "file:${{java.ext.dirs}}/*" {


        permission java.security.AllPermission;



};



// default permissions granted to all domains


grant {


    permission java.security.AllPermission;


    //permission java.lang.reflect.ReflectPermission "suppressAccessChecks";


};




grant {


        permission java.util.PropertyPermission "*", "read, write";


  permission java.lang.RuntimePermission "getProtectionDomain";


  permission java.io.FilePermission "<<ALL FILES>>", "read, write, delete, execute";


  permission java.io.SerializablePermission "enableSubstitution";


  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";


  permission java.lang.RuntimePermission "accessClassInPackage.org.apache.*";


  permission java.lang.RuntimePermission "accessClassInPackage.sun.*";


  permission java.lang.RuntimePermission "accessDeclaredMembers";


  permission java.lang.RuntimePermission "createClassLoader";


  permission java.lang.RuntimePermission "getClassLoader";


  permission java.lang.RuntimePermission "loadLibrary.libtcnative-1";


  permission java.lang.RuntimePermission "loadLibrary.management";


  permission java.lang.RuntimePermission "loadLibrary.net";


  permission java.lang.RuntimePermission "loadLibrary.tcnative-1";


  permission java.lang.RuntimePermission "modifyThread";


  permission java.lang.RuntimePermission "modifyThreadGroup";


  permission java.lang.RuntimePermission "org.jboss.security.SecurityAssociation.setServer";


  permission java.lang.RuntimePermission "setContextClassLoader";


  permission java.lang.RuntimePermission "createSecurityManager";


  permission java.lang.RuntimePermission "setFactory";


  permission java.lang.RuntimePermission "setIO";


  permission java.lang.RuntimePermission "shutdownHooks";


  permission java.net.NetPermission "specifyStreamHandler";


  permission java.net.SocketPermission "*", "listen, resolve, connect, accept";


  permission java.security.SecurityPermission "createAccessControlContext";


  permission java.security.SecurityPermission "getDomainCombiner";


  permission java.security.SecurityPermission "getPolicy";


  permission java.security.SecurityPermission "getProperty.*";


  permission java.security.SecurityPermission "insertProvider.SUN";


  permission java.security.SecurityPermission "putProviderProperty.SUN";


  permission java.security.SecurityPermission "setPolicy";


  permission java.security.SecurityPermission "setProperty.package.access";


  permission java.security.SecurityPermission "setProperty.package.definition";


  permission net.jini.security.GrantPermission "java.security.AllPermission";


  permission com.sun.jini.discovery.internal.EndpointInternalsPermission "set";


  permission com.sun.jini.discovery.internal.EndpointInternalsPermission "get";


  permission java.util.logging.LoggingPermission "control";


  permission net.jini.discovery.DiscoveryPermission "*";


  permission javax.security.auth.AuthPermission "refreshLoginConfiguration";


  permission javax.security.auth.AuthPermission "setLoginConfiguration";


  permission javax.management.MBeanServerPermission "createMBeanServer";


  permission javax.management.MBeanServerPermission "findMBeanServer";


  permission javax.management.MBeanServerPermission "newMBeanServer";


  permission javax.management.MBeanTrustPermission "register";


  permission javax.management.MBeanPermission "*", "*";


  permission java.lang.RuntimePermission "org.jboss.security.SecurityAssociation.setRunAsRole";


  permission javax.security.auth.AuthPermission "doAsPrivileged";


  permission java.lang.RuntimePermission "org.jboss.security.SecurityAssociation.getPrincipalInfo";


  permission javax.security.auth.AuthPermission "createLoginContext.HsqlDbRealm";


  permission javax.security.auth.AuthPermission "getLoginConfiguration";


  permission java.lang.RuntimePermission "org.jboss.security.SecurityAssociation.accessContextInfo";


  permission javax.security.auth.PrivateCredentialPermission "javax.resource.spi.security.PasswordCredential * \"*\"", "read";


  permission javax.security.auth.AuthPermission "*";


  permission java.lang.RuntimePermission "org.jboss.security.SecurityAssociation.setPrincipalInfo";


  permission net.jini.security.GrantPermission "java.security.AllPermission \"<all permissions>\", \"<all actions>\"";


  permission net.jini.export.ExportPermission "exportRemoteInterface.com.sun.jini.reggie.Registrar";


  permission com.sun.jini.thread.ThreadPoolPermission "getSystemThreadPool";


  permission javax.management.MBeanServerPermission "releaseMBeanServer";


  permission java.lang.RuntimePermission "exitVM";



};





Code: I would like to show one JSP code with phpmyadmin(xampp) with ODBC connection, you can try your end. I hope you know little bit JSP syntax and command.



<html>

<head>

  <title>Book Query</title>

</head>

<body>

  <h1>List of enrolled Students</h1>



  <%@ page import = "java.sql.*" %>







  <%

       Connection conn = null;

        try

        {

            String userName = "root";

            String password = "";

            Class.forName ("com.mysql.jdbc.Driver").newInstance ();



            String url = "jdbc:mysql://127.0.0.1:3306/student";



            conn = DriverManager.getConnection (url, userName, password);



 Statement stmt = conn.createStatement();

 String sqlStr = "SELECT * FROM stu_info1 order by id desc";



            ResultSet rset = stmt.executeQuery(sqlStr);

 %>

 <table border='1'>

        <tr>

           <th>ID</th>

          <th>Name</th>

          <th>city</th>

          <th>Gender</th>

          <th>Phone</th>

          <th>Email</th>

          <th>Dob</th>

          <th>Address</th>

          <th>Qualification</th>

          <th>Courses</th>

          <th>Action</th>

        </tr>

 <%

 while (rset.next()) {

 %>

 <tr>

            <td><%= rset.getInt("id") %></td>

            <td><%= rset.getString("Name") %></td>

            <td><%= rset.getString("Gender") %></td>

            <td><%= rset.getString("city") %></td>

            <td><%= rset.getString("Phone") %></td>

            <td><%= rset.getString("Email_id") %></td>

            <td><%= rset.getInt("Birthday_day")+","+rset.getString("Birthday_Month")+" "+rset.getInt("Birthday_Year")  %></td>

            <td><%= rset.getString("Address") %></td>

 <td><table border="0" cellpadding="4"  cellspacing="0" style="border: 2px solid  #ccc;">



 <tr>

 <td align="center"><b>Sl.No.</b></td>

 <td align="center"><b>Examination</b></td>

 <td align="center"><b>Board</b></td>

 <td align="center"><b>Percentage</b></td>

 <td align="center"><b>Year of Passing</b></td>

 </tr>



 <tr>

 <td>1</td>

 <td>Class X</td>

 <td><input type="text" name="ClassX_Board" maxlength="30" value="<%= rset.getString("ClassX_Board") %>"/></td>

 <td><input type="text" name="ClassX_Percentage" maxlength="30" value="<%= rset.getInt("ClassX_Percentage") %>"/></td>

 <td><input type="text" name="ClassX_YrOfPassing" maxlength="30" value="<%= rset.getInt("ClassX_YrOfPassing") %>"/></td>

 </tr>



 <tr>

 <td>2</td>

 <td>Class XII</td>

 <td><input type="text" name="ClassXII_Board" maxlength="30" value="<%= rset.getString("ClassXII_Board") %>"/></td>

 <td><input type="text" name="ClassXII_Percentage" maxlength="30" value="<%= rset.getString("ClassXII_Percentage") %>"/></td>

 <td><input type="text" name="ClassXII_YrOfPassing" maxlength="30" value="<%= rset.getString("ClassXII_YrOfPassing") %>"/></td>

 </tr>



 <tr>

 <td>3</td>

 <td>Graduation</td>

 <td><input type="text" name="Graduation_Board" maxlength="30" value="<%= rset.getString("Graduation_Board") %>"/></td>

 <td><input type="text" name="Graduation_Percentage" maxlength="30" value="<%= rset.getString("Graduation_Percentage") %>"/></td>

 <td><input type="text" name="Graduation_YrOfPassing" maxlength="30" value="<%= rset.getString("Graduation_YrOfPassing") %>"/></td>

 </tr>

 </table></td>

 <% if(rset.getString("Course_BCom")!=null){

 %>

 <td><%= rset.getString("Course_BCom")%></td>

 <%

 }

 %>

 <% if(rset.getString("Course_BCA")!=null){

 %>

 <td><%= rset.getString("Course_BCA")%></td>

 <%

 }

 %>

 <% if(rset.getString("Course_BCom")!=null){

 %>

 <td><%= rset.getString("Course_BCom")%></td>

 <%

 }

 %>

 <td>

 <a href="edit.jsp?edit=edit&id=<%= rset.getInt("id")%>">Edit </a>

 <br>

 <a href="prepared_statement_query.jsp?del=del&id=<%= rset.getInt("id") %>">Delete</a>

 <br>

 <a href= "prepared_statement_query.jsp">Add</a>

 </td>

        </tr>

   <%

 }



        }

        catch (Exception e)

        {

            System.out.println ("Cannot connect to database server");

        }





  %>



  </table>

</body>

</html>

 Requirment :  JSp , Tomcate , Xampp Server , java.policy file, mysql-connector .jar 









Comments