简体   繁体   English

如何将jsp页面中的数据插入mysql数据库并从Eclipse内部对该表运行查询?

[英]How to insert data from a jsp page into mysql database and run queries on that table , from inside Eclipse?

I have the following JDBC connection with mysql database : 我与mysql数据库具有以下JDBC连接:

import java.sql.*;

public class Main
{
    public static void main (String[] args) throws ClassNotFoundException, SQLException
    {

        Class.forName("com.mysql.jdbc.Driver");

        String string = "jdbc:mysql://localhost:3306/testdb";

        Connection con = DriverManager.getConnection(string , "root2" , "root");
        PreparedStatement statement = con.prepareStatement("select * from names"); // SELECT * FROM `names`
        ResultSet result = statement.executeQuery();
        while (result.next())
        {
            System.out.println(result.getString(1) + " " + result.getString(2));
        }


    }
}

When I go into http://localhost/phpmyadmin and create a database , I can run successfully queries on the database the I made there , but how can I do that from inside Eclipse (eg java) ? 当我进入http://localhost/phpmyadmin并创建数据库时,可以在我在那里创建的数据库上成功运行查询,但是如何从Eclipse (例如Java)内部执行查询呢?

To be more clear, the user enters data into a jsp page , and I extract the data from there . 更清楚地说,用户将数据输入到jsp页面中,然后从中提取数据。 After that , I want to create a database from inside Eclipse , without going directly into http://localhost/phpmyadmin . 之后,我想从Eclipse内部创建数据库,而不必直接进入http://localhost/phpmyadmin How can I do that ? 我怎样才能做到这一点 ?

EDIT: 编辑:

I have the needed servlets , what I want now is to create the database from the servlet and run the queries from the servlet . 我有所需的servlet,我现在要从servlet创建数据库并从servlet运行查询。

Thanks 谢谢

Complete answer to your question will require a lot of writing and few clarifications. 要完全回答您的问题,将需要大量的文字和少量的澄清。

There is excellent tutorial which you can use: Creating Database Web Applications with Eclipse 您可以使用出色的教程: 使用Eclipse创建数据库Web应用程序

Instead of Derby DB you will use MySQL. 代替Derby DB,您将使用MySQL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM