I have the following JDBC
connection with mysql database :
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) ?
To be more clear, the user enters data into a jsp
page , and I extract the data from there . After that , I want to create a database from inside Eclipse , without going directly into 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 .
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
Instead of Derby DB you will use MySQL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.