在终端中创建sqlite DB,但在Java程序(Mac)中连接到它
我正在写一个处理客户信息的基本程序。我在数据库部分遇到了一些问题(我从未用SQL或数据库编写过任何代码)。我的问题是。。。 如果我在Terminal中创建一个Sqlite数据库(b/c,似乎比在JAVA中更容易),并给它一个表,那么我如何在JAVA代码中连接到该数据库?我在tutorialspoint.com上看过Sqlite java教程,但似乎无法理解。真的很难受。我感谢所有的意见! 注意:我想用对数据库的SQL调用替换名为“table”的数组。 这是我的密码:在终端中创建sqlite DB,但在Java程序(Mac)中连接到它,java,sql,sqlite,Java,Sql,Sqlite,我正在写一个处理客户信息的基本程序。我在数据库部分遇到了一些问题(我从未用SQL或数据库编写过任何代码)。我的问题是。。。 如果我在Terminal中创建一个Sqlite数据库(b/c,似乎比在JAVA中更容易),并给它一个表,那么我如何在JAVA代码中连接到该数据库?我在tutorialspoint.com上看过Sqlite java教程,但似乎无法理解。真的很难受。我感谢所有的意见! 注意:我想用对数据库的SQL调用替换名为“table”的数组。 这是我的密码: import java.aw
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
public class Gui extends JFrame {
//Create the frame.
public Gui() {
//General window commands
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = (int) screenSize.getWidth();
int screenHeight = (int) screenSize.getHeight();
final int programWidth = (int) ((double) screenWidth * 0.70);
int programHeight = (int) ((double) screenHeight * 0.65);
setBounds(screenWidth/9, screenHeight/10 /*or 90*/,programWidth, programHeight);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*CREATING TAB NUM 1 CLIENTALE
Table column names*/
String[] columnNames = {"First Name",
"Last Name",
"Car Year",
"Car Make",
"Mileage"};
//Putting Data into the table
//Will be replaced with SQL references
Object[][] data = {
{"Colbey","Hatcher", new Integer(1997),
"Mazda", new Integer(99999)},
{"Emilia","Ryan", new Integer(2012),
"Honda", new Integer(10000)}};
//Table must be created after creation of Column Names and Data
JTable table = new JTable(data, columnNames);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
//END OF TAB NUM 1 CLIENTALE
//SETTING UP TABBED PANE & IMPLEMENTING CONTENT FROM ABOVE
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("CUSTOMER TOTAL", scrollPane);
//tabbedPane.addTab("NEW CUSTOMER", splitPane);
//Adds everything above into the JFrame
add(tabbedPane);
//END OF TABE PANE SET UP
}//end of constructor
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Gui frame = new Gui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}//end of public static
}//end of jFrame