微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我使用哪种简单的数据库解决方案将解析的变量从eclipse提取到数据库

如何解决我使用哪种简单的数据库解决方案将解析的变量从eclipse提取到数据库

您可以使用MysqL数据库

1)下载mysql连接器,然后将jar添加到您的项目中。

2)在db中创建一个表,并使用该表在其中插入值。

数据库的Java代码

public class Database {
    private Connection connection = null;
    private Statement statement = null;
    private String serverName = null;
    private String dbname = null;
    private String  dbtablename = null;
    private String username = null;
    private String password = null;

   public Database() {
        serverName = //your value;
        dbname = your value
        dbtablename = //your value
        username = //your value
        password = //your value
    }

   public Connection OpenConnectionDB() {
        try {

            Class.forName("com.MysqL.jdbc.Driver").newInstance();
            this.connection = DriverManager.getConnection("jdbc:MysqL://" + serverName + "/" + dbname + "?useUnicode=yes&characterEncoding=UTF-8&" + "user=" + username + "&password=" + password);
            System.out.println("conection: " + connection);
            //            this.connection = DriverManager.getConnection("jdbc:MysqL://" + serverName + "/" + dbname  +"?user=" + username + "&password=" + password );
            //System.out.println("debug: Connect to dbServer");

        } catch (sqlException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        } catch (illegalaccessexception ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        return connection;
    }

    public void closeConnectionDB() {
        if (this.connection != null) {
            try {
                connection.close();
                connection = null;
                //System.out.println("debug: Close dbServer");
            } catch (sqlException ex) {
                System.out.println("debug: Closing Database... Failed (NOT RUNNING)");
                Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void insert(){
         String query = //your insert query
         OpenConnectionDB();
         try {
            this.statement = this.connection.createStatement();
                this.statement.execute(query);
                statement.close();
        } catch (sqlException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        closeConnectionDB();
    }

   public String getResults(){
        String query = //select query
        OpenConnectionDB();
        try {
            this.statement = this.connection.createStatement();
            ResultSet  rs = this.statement.executeQuery(query);

            if(rs!=null){
                while(rs.next()){
                    return rs.getString("Your_field_name_in_db"); //get your 
                }            
            }

             statement.close();
        } catch (sqlException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        closeConnectionDB();
        return null;
    }


}

您也可以使用MySQL WorkBench处理您的数据库

解决方法

我测试了一些解析,并得到了字符串。现在,我想将其写入本地数据库,以查看以后是否可以在更大范围内进行操作。我选择哪种数据库容易处理?第一步是什么?

/编辑。我用日食工作。而且我对编程还很陌生。安装了MS SQL Express,但是我不知怎么处理。不知道从哪里开始…

非常感谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。