The 11th chapter of textbook Learning content
MySQL database management system, referred to as MySQL, is the world's most popular open source database management system, its Community edition (MySQL Community Edition) is the most popular free download open source database management system.
Start:
At the command line, enter the bin subdirectory of the MySQL installation directory, and type the mysqld--initialize-insecure command:
D:\mysql-5.7.15-winx64\bin>mysqld--initialize-insecure
The function is to initialize the data directory and authorize a root user without a password. After successful execution, the MySQL installation directory has a more data subdirectory (for the database, for the previous version, the directory after installation)
Load Jdbc-mysql Database driver:
try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){}
To connect to a database:
Using Connection getConnection(java.lang.String)
methods to establish a connection
For example:
Connection con;String uri = "jdbc:mysql://192.168.100.1:3306/students?user=root&password=&useSSL=true";try{ con = DriverManager.getConnection(uri); //连接代码 }catch(SQLException e){ System.out.println(e);}
Query
SQL query Statement object:
try{ Statement sql=con.createStatement();}catch(SQLException e ){}
Working with query results:ResultSet rs = sql.executeQuery("SELECT * FROM students");
To close the connection:
In the Code
ResultSet rs = sql.executeQuery("SELECT * FROM students");
Close the connection immediately after
Control cursors
Use this method to obtain a statement object:Statement stmt = con.createStatement(int type ,int concurrency);
Connecting to a SQL Server database
try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}catch(Exception e){}
Problems in code debugging and the resolution process
- Issue 1: Error running Example11_1
- Problem 1 The solution requires you to download MySQL first in your computer, otherwise you will get an error running the program.
Code Hosting
Last week's summary of the wrong quiz
Wrong Title 1:
- The following is an explanation of the exception, the wrong is a D
A. Java throws an exception using throws, which may throw an exception using the throw declaration method.
B. Executes System.out.println (3/0); The statement will report an ArithmeticException exception.
C. The errors in Java are the various subclass instances that are rendered as objects as java.lang.Throwable.
D. Method parseint () may throw dataformatexception exceptions during execution.
Item A: Java throws an exception using throw, and using the throws declaration method may throw an exception. D: The numberformatexception exception may be thrown.
Wrong Title 2:
- The following statement about exception handling, the correct is a C D
A. Once the try section throws an exception object, the try section immediately ends execution and turns to the corresponding catch section.
B. A catch code block defines code that is bound to execute, which is typically used to close a resource.
C. The Try-catch statement can consist of several catch, dealing with the exception that occurs.
D. Exceptions listed in the catch brackets must not have an inheritance relationship, or a compilation error will occur.
B: The finally code block defines code that is bound to execute, which is typically used to close a resource. For the exception of the part, if not done finally, then the program is flawed, each call to the resources and then release the resources is necessary, otherwise the operating pressure will be particularly large.
Wrong Title 3:
- What exception objects are thrown by the interrupt () method of the calling thread? ADE
A. Closedbyinterruptexception
B. IllegalStateException
C. RuntimeException
D. Interruptedexception
E. SecurityException
Query Api:b entry: The character at index EndIndex-1. E entry: Throws a Indexoutofboundsexception exception.
Wrong Title 4:
- The following is the file class construction method that is the ABCD
A. File (file parent, String child)
B. File (String pathname)
C. File (string parent, String child)
D. File (URI Uri)
Wrong title 5:
- The InputStream class inherits from FileInputStream and can read the file in bytes. B
A. True
B. False
Learning progress Bar
|
lines of code (new/cumulative) |
Blog Volume (Add/accumulate) |
Learning Time (new/cumulative) |
Important Growth |
Goal |
5000 rows |
30 Articles |
400 hours |
|
First week |
200/200 |
1/4 |
10/10 |
|
Second week |
300/500 |
1/5 |
10/20 |
|
Third week |
800/1300 |
1/6 |
20/40 |
|
Week Four |
700/2000 |
2/8 |
20/60 |
|
Week Five |
1100/3100 |
2/10 |
30/90 |
|
Week Six |
1100/4200 |
1/11 |
15/105 |
|
Seventh Week |
500/4700 |
3/14 |
20/125 |
|
Eighth Week |
|
|
|
|
Resources
20165231 2017-2018-2 "Java Programming" 7th Week study Summary