We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › MySQL discrepancies
Page Index Toggle Pages: 1
MySQL discrepancies? (Read 641 times)
MySQL discrepancies?
Feb 23rd, 2007, 11:20am
 
i have written a simple program that displays a map. the map is composed of 9 rows and 9 columns, each of which holds a 32px by 32px tile. everything is loaded from BLOBs in a MySQL database.

the program runs fine locally, and all of the images are displayed properly. when i export the program and even view it locally in internet explorer, all i get is the background color and an empty frame. the same happens when i run the .exe compiled version and the  .jar compiled version (which is what IE is loading from index.html i guess). the program will only display the images if i run it from within the Processing IDE.

any ideas why? does it have something to do with using the JDBC?

here is my entire program:

Code:
import java.awt.Image; 
import java.io.BufferedInputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.imageio.ImageIO;

ArrayList tiles = new ArrayList();
int[][] map = new int[9][9];
int x, y;

void setup()
{
grabTiles();
x = 4;
y = 4;
grabMap("newbie_zone");
size(288, 288);
background(0);
}

void draw()
{
for(int a = 0; a < 9; a++)
for(int b = 0; b < 9; b++)
image((PImage) tiles.get(map[a][b]), a * 32, b * 32);

noLoop();
}

void grabTiles()
{
Connection conn = null;
ResultSet rs = null;
BufferedInputStream is = null;

try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost:3306/rpg";
String user = "rpg";
String password = "rpg";
int a = 0;

conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select distinct blob_id from tiles__map");
rs.last();
int numTiles = rs.getRow();

try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}

rs = stmt.executeQuery("select blob_content, blob_id from tiles__map order by blob_id asc");

while (rs.next()) {
// retrieve the image using ImageIO
Blob blob = rs.getBlob("blob_content");
is = new BufferedInputStream(blob.getBinaryStream());
Image raw = ImageIO.read(is);
PImage norm = new PImage(raw);
tiles.add(a++, norm);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (Exception e) {
e.printStackTrace();
}

try {
rs.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

void grabMap(String mapName)
{
String tbl = "map__" + mapName;
Connection conn = null;
ResultSet rs = null;

try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost:3306/rpg";
String user = "rpg";
String password = "rpg";

conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select distinct x from " + tbl);
rs.last();
int rows = rs.getRow();

try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}

rs = stmt.executeQuery("select distinct y from " + tbl);
rs.last();
int cols = rs.getRow();

try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}

rs = stmt.executeQuery("select x, y, tile from " + tbl + " where "
+ "x >= " + (x - 4) + " AND "
+ "x <= " + (x + 4) + " AND "
+ "y >= " + (y - 4) + " AND "
+ "y <= " + (y + 4)
+ " order by x asc, y asc");
rs.last();
int rowCount = rs.getRow();
rs.first();

for(int a = 0; a < 9; a++)
for(int b = 0; b < 9; b++)
if(rs.getInt("x") != a || rs.getInt("y") != b){
map[b][a] = 0;
} else {
map[b][a] = rs.getInt("tile");
rs.next();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Re: MySQL discrepancies?
Reply #1 - Feb 23rd, 2007, 11:32am
 
i'm sorry if this forces the post to be off topic for the forum, but is it perhaps not MySQL, but that an AWT Image method is being used?

i was reading in the FAQ something about shying away from AWT methods. if this is the case, i guess i'll have to read up on embedding my projects in a native java environment.. though i'm not really a java programmer, so there's another page to turn Cheesy
Page Index Toggle Pages: 1