Jump to content
  • 0

Get Info From Database to Community


Question

Posted

Hello! i'm trying to show info from database into CommunityBoard. I would like to show, if the clan has ClanHall or Fortress, etc. I write this but its getting an error and i dont know why.

 

java.sql.SQLException: Before start of result set
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
        at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:781)
        at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5239)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5162)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5201)
        at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
        at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
        at l2r.gameserver.model.L2Clan.getHideOutName(L2Clan.java:3014)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.clanhome(ClanBBSManager.java:253)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.clanhome(ClanBBSManager.java:234)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.cbByPass(ClanBBSManager.java:50)
        at l2r.gameserver.communitybbs.BoardsManager.handleCommands(BoardsManager.java:80)
        at l2r.gameserver.network.clientpackets.RequestBypassToServer.runImpl(RequestBypassToServer.java:251)
        at l2r.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:71)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

 

 

This is the backEnd.

 

public String getHideOutName(int ownerId)
	{
		String x = null;
		
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT DISTINCT name FROM `clanhall` cl INNER JOIN `clan_data` c ON cl.ownerId = ?");)
		{
			ps.setInt(1, ownerId);
			ResultSet rs = ps.executeQuery();
			
			x = rs.getString("name");
			
		}
		catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (x == null)
		{
			return "None";
		}
		return x;
	}

 

Please, someone can give me a hand with this?.
Thanks!!

3 answers to this question

Recommended Posts

  • 1
Posted (edited)
1 hour ago, barao45 said:

Hello! i'm trying to show info from database into CommunityBoard. I would like to show, if the clan has ClanHall or Fortress, etc. I write this but its getting an error and i dont know why.

 

java.sql.SQLException: Before start of result set
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
        at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:781)
        at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5239)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5162)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5201)
        at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
        at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
        at l2r.gameserver.model.L2Clan.getHideOutName(L2Clan.java:3014)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.clanhome(ClanBBSManager.java:253)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.clanhome(ClanBBSManager.java:234)
        at l2r.gameserver.communitybbs.Managers.ClanBBSManager.cbByPass(ClanBBSManager.java:50)
        at l2r.gameserver.communitybbs.BoardsManager.handleCommands(BoardsManager.java:80)
        at l2r.gameserver.network.clientpackets.RequestBypassToServer.runImpl(RequestBypassToServer.java:251)
        at l2r.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:71)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

 

 

This is the backEnd.

 

public String getHideOutName(int ownerId)
	{
		String x = null;
		
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT DISTINCT name FROM `clanhall` cl INNER JOIN `clan_data` c ON cl.ownerId = ?");)
		{
			ps.setInt(1, ownerId);
			ResultSet rs = ps.executeQuery();
			
			x = rs.getString("name");
			
		}
		catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (x == null)
		{
			return "None";
		}
		return x;
	}

 

Please, someone can give me a hand with this?.
Thanks!!

First it is necessary to know if what you need is to recover one or several values, if you need several then you must add the values of the result in a list but the following form:
while(rs.next()){ list.add(rs.getString("name")); }
And if you only need to retrieve a single value which is what I assume you want to do, you should limit your result to a by placing at the end of your query Limit 1
And you could put your assignment like this:
x = (rs.getString("name") != null) ? rs.getString("name") : "None";

Edited by TGSLineage2
Guest
This topic is now closed to further replies.


  • Posts

    • Looks like somebody discovered AI recently
    • Added: Server monitoring has been added to the protection dashboard, available for Premium+ plans. Each entry displays: Account — game login. HWID — hardware ID. GSID — the game server the entry belongs to. IP — the player's address. Country — determined by IP, with flag and name. Useful for SEO promotion, do you know where more players come from Status — "Banned" or "OK". Extra windows — how many additional windows are allowed for this HWID beyond the global limit. Last seen — time of last activity.   At the top — a summary: total entries, number banned, time of the last report, and an Online/Offline indicator (based on how fresh the data from the protection is).   Filters and search Search by account, HWID, or IP. Country — select from countries actually present in the data. Game server (GS) — filter by GSID. Period — by last activity date (from / to). Banned only — quick filter for violators. Grouping — collapse data by HWID, IP, or account: one row per key with counts of accounts/HWIDs/IPs and number of entries. Handy for catching multi-accounters (many accounts from one HWID) and suspicious IPs.   Ban / Unban — banning by HWID blocks all accounts on that hardware. The protection will pick up the command within a minute; until applied, a "Pending…" status is shown. Grant windows — set additional windows (+N) for a specific HWID via a convenient selector. Single token per account to link the protection with the dashboard: Generate / Reissue token in one click. Show token — view the current value at any time. The token is stored encrypted. Don't share it with anyone — if compromised, simply reissue it and the old one stops working immediately. In the protection config, you can enable monitoring, insert the token, and change how often data is sent to the protection dashboard.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..