One, about JDBC
The last week is learning jdbc for a whole day, in accordance with the above teaching, has mastered the basic knowledge of JDBC syntax, and can complete the function of the deletion check, the following is my code and running results show.
1, about how JDBC is a database and Java code are linked on the myeclipse.
Package CN.ITCAST.JDBC;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
public class Base {
public static void Main (string[] args) throws Exception {
Template ();
}
static void Template () throws exception{
Connection Conn=null;
Statement St=null;
ResultSet Rs=null;
try {
2. Establish a connection
Conn=jdbcutils.getconnection ();
3. Create a statement
St=conn.createstatement ();
4. Execute the statement
Rs=st.executequery ("select* from user");
5. Processing results
while (Rs.next ()) {
System.out.println (Rs.getobject (1) + "\ T" +rs.getobject (2) + "\ T" +rs.getobject (3) + "\ T" +rs.getobject (4));
}
}finally{
Jdbcutils.free (RS, St, conn);
}
}
static void Test () throws SQLException, classnotfoundexception{
1. Registration Driver
Drivermanager.registerdriver (New Com.mysql.jdbc.Driver ());//Method One
System.setproperty ("jdbc", "com.mysql.jdbc.Driver");//Mode Two
Class.forName ("Com.mysql.jdbc.Driver");//Method Three, better, even without MySQL can be compiled by
Method four, command-line
2. Establish a connection
String url= "Jdbc:mysql://localhost:3306/jdbc";
String user= "root";
String password= "hyq123";
Connection conn=drivermanager.getconnection (Url,user,password);
3. Create a statement
Statement st=conn.createstatement ();
4. Execute the statement
ResultSet rs=st.executequery ("select* from user");
5. Processing results
while (Rs.next ()) {
System.out.println (Rs.getobject (1) + "\ T" +rs.getobject (2) + "\ T" +rs.getobject (3) + "\ T" +rs.getobject (4));
}
6. Releasing Resources
Rs.close ();
St.close ();
Conn.close ();
}
}
This is the code that implements the database connection, where the database connection takes six steps.
2. The function display (in the form) of adding or deleting changes
These statements enable modifications to the database on the Java console
In this process is full of hardships, at first I did not contact MySQL for a while, and then open the statement should be mysql-uroot-p, but I wrote the MySQL uroot-p, so I entered the password after the 10045 error, to search the Internet solution , but a lot of people say that MySQL is not installed, and finally I found a solution, that is I looked at the blog before I wrote the garden, I saw the command line, suddenly, or very happy, MySQL does not have to reinstall.
3. How MySQL stores large files and images (also shown in the main code and format)
1) image
2) Large File
Second, self-perception
Time is really urgent, feel oneself to achieve here is not far away from success, database is I think this project is the most important and the most difficult part, so this week is very rewarding very happy!
Introduction to Software engineering seventh week homework, about the project of the broken Read (a)