php mysql json example

$link = mysql_pconnect(“localhost”, “root”, “”) or die(“Could not connect”);mysql_select_db(“cdcol”) or die(“Could not select database”); $arr = array();$rs = mysql_query(“SELECT id, titel FROM cds”); while($obj = mysql_fetch_object($rs)) {    $arr[] = $obj;} echo ‘{“sample”:’.json_encode($arr).’}’;?>

Read More »

ext-js gui template

the code below is to be used with the following web based ext-js designer http://www.projectspace.nl/ 12345678910111213<pre> Ext.onReady(function(){     var movie_form = new Ext.FormPanel({         url: ‘data/movie-form-submit.jsp’,         renderTo: document.body,         frame: true,         title: ‘Movie Information Form’,         width: […]

Read More »

JDBC JSON JSTL example

put this code in index.jsp <%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” prefix=”sql” %> <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %> <%@ taglib prefix=”json” uri=”http://www.atg.com/taglibs/json” %> <sql:query var=”rs” dataSource=”jdbc/TestDB”> select prod_code, description from product_code </sql:query> {success:true,rows: <json:array name=”rows” prettyPrint=”true”> <c:forEach var=”row” items=”${rs.rows}”> <json:object> <json:property name=”prod_code” value=”${row.prod_code}”/> <json:property name=”description” value=”${row.description}”/> </json:object> </c:forEach> </json:array> }

Read More »

Generate XML with JSTL and SQL

from http://krook.net/archives/210 <%@ page contentType=“text/xml; charset=UTF-8″ pageEncoding=“UTF-8″ session=“false”%> <?xml version=“1.0″ encoding=“UTF-8″ ?> <%@ taglib prefix=“sql” uri=“http://java.sun.com/jsp/jstl/sql” %><%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %> <sql:setDataSource dataSource=“jdbc/yourdatasource”/> <sql:query var=“items”>  SELECT ID id, TITLE title, ABSTRACT abstract, BODY body, THUMBNAIL thumbnail    FROM NEWS_ARTICLES NA, NEWS_ARTICLE_IMAGES NAI    WHERE NA.ID = NAI.NA_ID;</sql:query> <results> <c:forEach var=“row” items=“${items.rows}” >  <result id=“<c:out value=”${row.id}“/>“>    […]

Read More »

JDBC Driver URL Cheat Sheet

http://www.devx.com/tips/Tip/28818 A List of JDBC Drivers If you need to access a database with Java, you need a driver. This is a list of the drivers available, what database they can access, who makes it, and how to contact them. IBM AS400 jdbc:as400://<HOST>:<PORT>/<DB> com.ibm.as400.access.AS400JDBCDriver IBM DB2 jdbc:db2://:/ COM.ibm.db2.jdbc.app.DB2Driver JDBC-ODBC Bridge jdbc:odbc: sun.jdbc.odbc.JdbcOdbcDriver Microsoft SQL Server […]

Read More »

AS400 Iseries ODBC PHP connection

$server=”iseries”; #the name of the iSeries $user=”myusr”; #a valid username that will connect to the DB $pass=”mypassword”; #a password for the username #Connect to the Database with ODBC – $conn is defined and loaded using the “odbc_connect” PHP #directive. $conn=odbc_connect($server,$user,$pass); #you may have to remove quotes #Check Connection if ($conn == false) { echo “Not […]

Read More »

JSP page using JDBC in a scriptlet

<jsp:directive.page import=”java.sql.*” /><br /><span class=”boldcode”><jsp:scriptlet><br />Class.forName(“org.gjt.mm.mysql.Driver”);<br />Connection connection = <br /> DriverManager.getConnection(“jdbc:mysql://localhost:3306/test”, “”, “”);<br />Statement statement = connection.createStatement();<br />int changed = <br /> statement.executeUpdate(“update counters set hitCount = hitCount + 1 ” +<br /> “where page like ‘” + request.getRequestURI() + “‘”);<br />if (changed == 0) statement.executeUpdate(“insert counters(page) values(‘” +<br /> request.getRequestURI() + “‘)”);<br />ResultSet […]

Read More »