English 中文(简体)
Java - URLConnection for PHP$_GET Methods for MySQL
原标题:Java - URLConnection for PHP $_GET Methods for MySQL

这正是问题所在。 我试图利用MySQL JConnector为 Java,而人们却说不了,因为它可以包含你的详细内容,因此我告诉他们,我使用PHP文字使用PHP_GET方法URLs。 他们说,这将是罚款。 然而,我发现两个问题。

1) 速度缓慢。 至少需要4至5秒才能完成。 即便是当我向当地东道方说的话。

b) 它有许多法典。 Maybe 我只是错了吗?

在这里,我做了哪些工作!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.TextArea.*;
import java.util.*;
import java.net.*;
import java.applet.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class test extends JApplet
{
    public JTextArea c;

    public void init()
    {
        c = new JTextArea();
        add(c);
        c.append("Let s change the level!");
        try
        {
            URL game = new URL("http://localhost/mystikrpg/game.php?act=stats&username=Dan");
            URLConnection connection = game.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
            {
                String command = inputLine;
                System.out.println(command);
                String[] temp = command.split("\|");
                c.append("
You re Lvl is: " + temp[1]);
            }
            in.close();

            c.append("
Trying to update level...");
            String newLevel = "777";
            URL newGame = new URL("http://localhost/mystikrpg/game.php?act=updateLvl&username=Dan&lvl=" + newLevel);
            URLConnection levelConnection = newGame.openConnection();
            BufferedReader level_BR = new BufferedReader(new InputStreamReader(levelConnection.getInputStream()));

            URL updateLevelURL = new URL("http://localhost/mystikrpg/game.php?act=stats&username=Dan");
            URLConnection up_lvl_conn = updateLevelURL.openConnection();
            BufferedReader up_lvl_br = new BufferedReader(new InputStreamReader(up_lvl_conn.getInputStream()));
            String getLvl;

            while ((getLvl = up_lvl_br.readLine()) != null)
            {
                String[] newLvl = getLvl.split("\|");
                c.append("
You re NEW Lvl is: " + newLvl[1]);
                // newLvl[1] == newLevel
            }
            c.append("
Level update done!");

            level_BR.close();
            up_lvl_br.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

这里的答复是:

Let s change the level!
You re Lvl is: 123456
Trying to update level...
You re NEW Lvl is: 777
Level update done!

它虽然运作缓慢而且多半——我如何解决这个问题?

最佳回答

我将确保你的MySQL数据库有适当的索引。 http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html set!

但是,如果是你的PHP代码,造成这一问题,那么你就应该把这个问题说成是 Java。 由于《公共卫生法》涉及该数据库,因此,我的口号是被搁置的地方。

问题回答

The problem is that URLConnection is actually pretty slow. You could try passing the Proxy.NO_PROXY parameter to the openConnection, but it won t make it superfast. (1 to 3 seconds per call, so you re still using up a lot of time) An alternative to the HttpConnection could be the Jakarta Commons HttpClient.

事实上,对你水平进行更新的ur也令人感到非常不安:如果有人发现这一点,你会再有一整批使用你的游戏的che子。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签