[java] mysql string gavimas

    
  1. Atsijungęs

    domis045

    Pranešimai: 0

    Sveiki gal galit padeti, paaiskinti kaip padaryti kad galeciau sita palyginti su string. Niekaip neiseina. Noriu palyginti string ir daryti tam tikra patikrinima per mysql.
    Pvz
    if(updateDatabase(player) > 0){
    blablabla.....
    }

    public int updateDatabase(String player){
    		{
    			Connection con = null;
    			int number = 0;
    
    			try
    			{
    				con = L2DatabaseFactory.getInstance().getConnection(false);
    				final PreparedStatement statement = con.prepareStatement("SELECT rew1 FROM rewards WHERE obj_Id=?");
    				statement.setString(1, player);
    				final ResultSet rset = statement.executeQuery();
    
    				while(rset.next())
    				{
    					number = rset.getInt(1);
    				}
    
    				statement.close();
    				rset.close();
    			}
    			catch(SQLException e)
    			{
    				_log.severe("could not check existing char number");
    				e.printStackTrace();
    			}
    			finally
    			{
    				CloseUtil.close(con);
    			}
    			return number;
    		}
    	}
    

    Nelabai aiskiai isdesciau mintis bet turetumet suprasti :D
    30 Gruodžio 2013 - 19:55 / #1
  2. 
  3. Atsijungęs

    wewewe

    Pavadinimas: L2 žaidėjas

    Narys

    Pranešimai: 727

    Vartotojo apdovanojimai: 16

    nelabai suprantu ka su kuo nori lygint, bet if(updateDatabase(player) > 0) is pirmo zvilgsnio turetu veikt
    30 Gruodžio 2013 - 20:08 / #2
  4. 
  5. Atsijungęs

    domis045

    Pranešimai: 0

    Gaila bet ne, ismeta man errorus kad netinka argumentai, galiu visa koda imest bet bus makalyne :D

    package com.l2jfrozen.gameserver.model.actor.instance;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import java.util.logging.Level;
    
    import com.l2jfrozen.gameserver.model.actor.instance.L2NpcInstance;
    import com.l2jfrozen.gameserver.model.entity.Announcements;
    import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
    import com.l2jfrozen.gameserver.network.clientpackets.Say2;
    import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
    import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
    import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
    import com.l2jfrozen.gameserver.network.serverpackets.SocialAction;
    import com.l2jfrozen.gameserver.network.serverpackets.StatusUpdate;
    
    import javolution.text.TextBuilder;
    import com.l2jfrozen.Config;
    import com.l2jfrozen.gameserver.managers.GrandBossManager;
    import com.l2jfrozen.gameserver.managers.RaidBossPointsManager;
    import com.l2jfrozen.gameserver.model.L2Character;
    import com.l2jfrozen.gameserver.model.L2Summon;
    import com.l2jfrozen.gameserver.model.spawn.L2Spawn;
    import com.l2jfrozen.gameserver.network.SystemMessageId;
    import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
    import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
    import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
    import com.l2jfrozen.util.CloseUtil;
    import com.l2jfrozen.util.database.L2DatabaseFactory;
    import com.l2jfrozen.util.random.Rnd;
    
    
    public class L2NewbieInstance extends L2NpcInstance{
    
    	@Override
    	public String getHtmlPath(int npcId, int val)
    	{
    		String pom = "";
    		if(val == 0)
    		{
    			pom = "" + npcId;
    		}
    		else
    		{
    			pom = npcId + "-" + val;
    		}
    
    		return "data/html/mano/" + pom + ".htm";
    	}
    	@Override
    	public void showChatWindow(L2PcInstance player)
    	{
    		String filename = "data/html/npcdefault.htm";
    		filename = getHtmlPath(getNpcId(), 0); // Owner message window
    		NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
    		html.setFile(filename);
    		html.replace("%objectId%", String.valueOf(getObjectId()));
    		html.replace("%npcname%", getName());
    		player.sendPacket(html);
    
    		filename = null;
    		html = null;
    	}
    	SystemMessage sm;
    	/**
    	 * @param objectId
    	 * @param template
    	 */
    	@Override
    	public void onBypassFeedback(L2PcInstance player, String command){
    		StringTokenizer st = new StringTokenizer(command, " ");
    		String actualCommand = st.nextToken(); // Get actual command
    		if(actualCommand.equalsIgnoreCase("reward1")){
    			//player.addItem("Consume", 57, 11000, null, false);
    			// pavyzdys player.sendPacket(new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addNumber(110000).addItemName(57));
    			//player.sendMessage("You have gained 11000 Adena");
    			player.getInventory().addItem("Extract", 57, 110000, player,null);
    			player.sendPacket(new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(57));
    			// Inventory update
    			StatusUpdate su = new StatusUpdate(player.getObjectId());
    			su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    			player.sendPacket(su);
    			player.sendPacket(new ItemList(player, true));
    			//mysql
    			updateDatabase(player);
    		}
    		if(updateDatabase(player) ){
    			
    		}
    	}
    	public L2NewbieInstance(int objectId, L2NpcTemplate template)
    	{
    		super(objectId, template);
    		// TODO Auto-generated constructor stub
    	}
    	@Override
    	public void onSpawn(){
    		Announcements.getInstance().announceToAll("Reward manager spawned in world.");
    	}
    	public int updateDatabase(String player){
    		{
    			Connection con = null;
    			int number = 0;
    
    			try
    			{
    				con = L2DatabaseFactory.getInstance().getConnection(false);
    				final PreparedStatement statement = con.prepareStatement("SELECT rew1 FROM rewards WHERE obj_Id=?");
    				statement.setString(1, player);
    				final ResultSet rset = statement.executeQuery();
    
    				while(rset.next())
    				{
    					number = rset.getInt(1);
    				}
    
    				statement.close();
    				rset.close();
    			}
    			catch(SQLException e)
    			{
    				_log.severe("could not check existing char number");
    				e.printStackTrace();
    			}
    			finally
    			{
    				CloseUtil.close(con);
    			}
    			return number;
    		}
    	}
    
    	
    	String MANO1="update rewards set rew1= ? where obj_Id = ?";
    	String MANO2="INSERT INTO rewards VALUES (?,0,0,0,0,0,0,0,0);";
    }
    Paskutinį kartą redagavo: domis045 30 Gruodžio 2013 - 20:23
    30 Gruodžio 2013 - 20:23 / #3
  6. 
  7. Atsijungęs

    wewewe

    Pavadinimas: L2 žaidėjas

    Narys

    Pranešimai: 727

    Vartotojo apdovanojimai: 16

    klaida irgi parodyk
    30 Gruodžio 2013 - 20:25 / #4
  8. 
  9. Atsijungęs

    domis045

    Pranešimai: 0

    prepare-local:
    prepare-final:
    init:
    [mkdir] Created dir: C:Users*Desktop rozenassgameserveruildclasses
    version:
    [echo] L2jFrozen Gameserver Revision: exported
    compile:
    [javac] Compiling 1475 source files to C:Users*Desktop rozenassgameserveruildclasses
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] C:Users*Desktop rozenassgameserverhead-srccoml2jfrozengameservermodelctorinstanceL2NewbieInstance.java:88: error: method updateDatabase in class L2NewbieInstance cannot be applied to given types;
    [javac] if(updateDatabase(player) ){
    [javac] ^
    [javac] required: String
    [javac] found: L2PcInstance
    [javac] reason: actual argument L2PcInstance cannot be converted to String by method invocation conversion
    [javac] 1 error
    [javac] 1 warning

    BUILD FAILED

    Seip parasysiu ko noriu: Zaidejas pasiekia 20 lvl, getLevel(); patikrina ar 20 LVL, tada pakeicai ta value is 0 i 1, tada nebegauna dovanu :)
    Paskutinį kartą redagavo: domis045 30 Gruodžio 2013 - 20:41
    30 Gruodžio 2013 - 20:34 / #5
  10. 
  11. Atsijungęs

    wewewe

    Pavadinimas: L2 žaidėjas

    Narys

    Pranešimai: 727

    Vartotojo apdovanojimai: 16

    metodo updateDatabase argumentas turi but string tipo, jam duodi L2PcInstance objekta. Speju tau reikia zaidejo niko, tai i metoda perduok player.getName() ar kazka tokio. Jau tiksliai nebeatsimenu kaip ten uzvadinta yra.
    30 Gruodžio 2013 - 20:44 / #6
  12. 
  13. Atsijungęs

    domis045

    Pranešimai: 0

    Bandysiu dq :)
    30 Gruodžio 2013 - 20:50 / #7