Configuring the Java EE Development environment under eclipse
A. Configuring Tomcat windows-"Perferences->server->server runtime Environments->add ...
B.installes JREs, then click Add
The default standard VM is available, click Next, and then click Directory to select the path to the native JDK installation, finish.
Connection to the MySQL database
The thing to do with database connections is to use JDBC
The first thing to do is download jdbc, download it on the official website, and put its mysql-connector-java-5.1.13-bin.jar into Lib in the JDK.
Add the address of the jar file that you just put in the classpath;
Build engineering tests in Eclipse,
In the right-click Project->properties->java Build path->libraries-> Select Add External
JDBC has three jobs.
The first one is the load driver,
The second one is the connection
The third is to send information to the database and accept the results of the return operation of the database
The following is a simple
String driver= "Com.mysql.jdbc.Driver"; Driver Program
String url= "Jdbc:mysql://localhost:3306/db_name"; The url,db_name of the connection is the database name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). New Instance ();
Connection con=drivermanager.getconnection (Url,username,password);
Statement stm=con.createstatement ();
Stm.execute ("");
ResultSet rs=stm.executequery ("select * from 0);
Here's the code for the test:
Import java.sql.*;
public class Test
{
public static Connection getconnection () throws SQLException, ClassNotFoundException
{
String url = "jdbc:mysql://localhost:3306/studentinfo?user=root&password=83394843";//generally you use this.
Class.forName ("Com.mysql.jdbc.Driver");//Load to DriverManager
String userName = "root";
String password = "83394843";
Connection con = drivermanager.getconnection (Url,username,password);
return con;
}//the entire function is used to build the connection
public static void Main (string[] args)
{
try{
Connection con = getconnection ();
Statement sql = Con.createstatement ();
Sql.execute ("drop table if exists student");
Sql.execute ("CREATE TABLE student" (ID int not NULL auto_increment,name varchar (a) NOT null default ' name ', math int not nul L default 60,primary key (ID));
Sql.execute ("Insert student values (1, ' AAA ', ' 99 ')");
Sql.execute ("Insert student values (2, ' BBB ', ' 77 ')");
Sql.execute ("Insert student values (3, ' CCC ', ' 65 ')");
String query = "SELECT * from student";
ResultSet result = sql.executequery (query);
SYSTEM.OUT.PRINTLN ("Student table data as follows:");
System.out.println ("---------------------------------");
System.out.println ("School Number" + "+" name "+" + "math Score");
System.out.println ("---------------------------------");
int number;
String name;
String Math;
while (Result.next ())
{
Number = Result.getint ("id");
Name = result.getstring ("name");
Math = result.getstring ("math");
SYSTEM.OUT.PRINTLN (number + "+ name +" "+ math);
}
Sql.close ();
Con.close ();
}
catch (Java.lang.ClassNotFoundException e)
{
System.err.println ("ClassNotFoundException:" + e.getmessage ());
}
catch (SQLException ex)
{
System.err.println ("SQLException:" + ex.getmessage ());
}
}
}
Configuring the Java EE Development environment and connection to the MySQL database under Eclipse