Step 2 : Run... First , See the effect , Learn again Step 3 : Imitation and troubleshooting Step 4 : Test.java Step 5 : explain Step 6 : jar
SQLite It's a database , It is running in JVM Inside , So you don't need to be like mysql That has to be installed and configured independently , But just take it and use it ...
The old rule , First download the runnable project in the upper right corner , Configure to run , After confirming availability , Then learn what steps have been taken to achieve this effect .
function Test class , You can see the effect as shown in the figure ~
After ensuring that the runnable project can run correctly , Then strictly follow the steps in the tutorial , Imitate the code again .
The imitation process inevitably has code differences , As a result, the expected operation results cannot be obtained , At this moment, by comparison The correct answer ( Runnable project ) And your own code , To locate the problem . In this way , Learning is effective , Troubleshooting is efficient , It can obviously improve the learning speed , Across all the barriers on the way to learning . It is recommended to use diffmerge Software , Compare folders . Put your own project folder , Compare with my runnable project folder . This software is awesome , You can know which two files in the folder are wrong , And clearly marked Here is a green installation and use tutorial : diffmerge Download and use tutorials
The code is in the comments ~
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Test { public static void main(String[] args) { try { // Load driver , connect sqlite of jdbc Class.forName("org.sqlite.JDBC"); // Connect to the database how2j.db, You don't have to create it manually ... Connection connection = DriverManager.getConnection("jdbc:sqlite:how2j.db"); // Create connection object , yes Java An important interface for operating database Statement statement = connection.createStatement(); // Determine whether there is a table tables Existence of . If yes, delete statement.executeUpdate("drop table if exists hero"); // Create table statement.executeUpdate("create table hero(id int,name varchar(20),hp int)"); // Insert data statement.executeUpdate("insert into hero values(1,'Gareen','452')"); // Search the database , Put the search into the dataset ResultSet In ResultSet rSet = statement.executeQuery("select * from hero"); while (rSet.next()) { // Traverse this data set System.out.println("id:" + rSet.getInt(1)); System.out.println(" full name :" + rSet.getString(2)); System.out.println(" Blood volume :" + rSet.getString(3)); } rSet.close();// Close dataset connection.close();// Close database connection } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Because there is no third-party tool to link , So the code uses java Create a table structure .
The code demonstrates adding and querying , Delete and modify will not be demonstrated .... The database file is called how2j.db, yes Sqlite Database file , Will automatically create
Required to run the project jar Already included in the runnable project in the upper right corner lib Under the directory
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2019-03-05
Download project operation error out of memory
1 One answer
There are no good names Jump to the problem location Answer time :2019-03-30
The problem is not It's in jar There are no problems with the code in the package Just download the latest sqlite-jdbc.jar File Drag to lib In the file Right click servlet-api.jar, Right click “Build Path”---->"Add to Build Path " Then it's time to jar The package has been successfully added and can run normally
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|