J2ME数据库或数据管理

时间:2012-03-25 07:12:06

标签: java database java-me dictionary rms

我使用Netbeans IDE(J2ME)开发移动应用程序,这是一个字典,用于在用户输入单词时检索单词的含义。

如何在应用程序(.jar文件中)保存/检索任何数据库中的这些含义?任何方法?我必须分发这个应用程序。

2 个答案:

答案 0 :(得分:2)

使用java-me,你支持Record Management System (RMS),你可以存储少量数据,

很好的方法是存储很少的信息,当用户查询单词时查看它是否在本地RMS中,提供它,否则你make a webservice call到你的服务器并向用户提供信息

答案 1 :(得分:0)

字典是键/值数据结构,就像Hashtable一样。您可以将数据作为Java属性文件存储在jar文件中(http://docs.oracle.com/javase/tutorial/essential/environment/properties.html)。

由于Java ME没有java.util.Properties类,您必须手动加载。


    public class Properties extends Hashtable {

        public Properties(InputStream in) throws IOException {
            if (in == null) {
                throw new IllegalArgumentException("in == null");
            }

            StringBuffer line = new StringBuffer();

            while (readLine(in, line)) {
                String s = line.toString().trim();

                if (s.startsWith("#") == false) {
                    int i = s.indexOf('=');

                    if (i > 0) {
                        String key = s.substring(0, i).trim();
                        String value = s.substring(i + 1).trim();

                        put(key, value);
                    }
                }
                line.setLength(0);
            }
        }

        private boolean readLine(InputStream in, StringBuffer line) throws IOException {
            int c = in.read();

            while (c != -1 && c != '\n') {
                line.append((char)c);
                c = in.read();
            }

            return c >= 0 || line.length() > 0;
        }

        public String get(String key) {
            return (String) super.get(key);
        }
    }

这是一个示例


    InputStream is = getClass().getResourceAsStream("/dictionary.properties");
    Properties dictionary = new Properties(is);