用java设计一个数据库管理系统 如何用java做一个数据库
JAVA \u8bfe\u7a0b\u8bbe\u8ba1\u8fde\u63a5\u6570\u636e\u5e93 \u7528java\u7f16\u5199\u56fe\u4e66\u7ba1\u7406\u7cfb\u7edfimport java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public clss DBTest{
public DBTest(){
//\u52a0\u8f7d\u9a71\u52a8
try{
class.forName("com.mysql.jdbc.Driver");
//\u8bbe\u7f6e\u6570\u636e\u5e93\u7684\u8bbf\u95ee\u8def\u5f84
String url = "jdbc:mysql://localhost:3306//derby";
//\u8bbe\u7f6e\u7528\u6237\u540d\u548c\u5bc6\u7801
Properties info = new Properties();
info.setProperty("user","zhanghao");
info.setProperty("password","mima");
//\u83b7\u53d6\u8fde\u63a5
Connection conn = DriverManager.getConnection(url,info);
Statement stmt = conn.createStatement();
//\u7ec4\u7ec7\u67e5\u8be2\u8bed\u53e5
String sql = "select * form table_name";
//\u83b7\u53d6\u67e5\u8be2\u7ed3\u679c\u96c6\u5408
ResultSet result = stmt.excuteQuery(sql);
//\u904d\u5386\u7ed3\u679c,\u5047\u8bbetable_name\u4e2d\u7b2c\u4e00\u5217\u4e3aid,\u7c7b\u578bint
while(result.next()){
System.out.println(result.getInt(1));
}
}catch(SQLException){
}
catch(Exception e){
// e.printStackTrace();
}finally{
//\u6700\u540e\u5173\u95ed\u8d44\u6e90
result.close();
stmt.close();
conn.close();
}
}
}
//\u73b0\u573a\u624b\u6253 \u53ef\u80fd\u4f1a\u6709\u70b9\u4e0b\u9519\u8bef \u4f60\u81ea\u5df1\u6d4b\u8bd5\u4e0b \u5927\u81f4\u6d41\u7a0b\u5c31\u662f\u8fd9\u6837\u7684
\u4f60\u53ef\u4ee5\u628a\u4fe1\u606f\u5b58\u50a8\u5230\u4e00\u4e2afinal\u4fee\u9970\u7684Map\u4e2d\uff0c\u4e4b\u540eKey\u662f\u4e3b\u952eValue\u662f\u6570\u636e\u3002\u4e0d\u8fc7\u91cd\u542f\u4e4b\u540e\u6570\u636e\u5c31\u4f1a\u90fd\u4e22\u4e86
import java.sql.*;import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
//import java.awt.event.*;
public class DisplayDemo extends JFrame
//implements ActionListener
{
// private String dbURL="jdbc:microsoft:sqlserver://202.115.26.181:1433"; // 数据库标识名
private String user="devon"; // 数据库用户
private String password="book"; // 数据库用户密码
private JTable table;
private JButton ok,canel;
public DisplayDemo(){
super("显示数据库查询结果"); //调用父类构造函数
String[] columnNames={"用户名","年龄","性别","Email"}; //列名
Object[][] rowData=new Object[5][4]; //表格数据
ok=new JButton("确定");
canel=new JButton("取消");
// ok.addActionListener(this);
// canel.addActionListener(this);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:example","sa","");
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //加载驱动器
// Connection con=DriverManager.getConnection(dbURL,user,password); //获取连接
String sqlStr="select * from users"; //查询语句
PreparedStatement ps=con.prepareStatement(sqlStr); //获取PreparedStatement对象
ResultSet rs=ps.executeQuery(); //执行查询
String name,sex,email; //查询结果
int age;
int count=0;
while (rs.next()){ //遍历查询结果
rowData[count][0]=rs.getString("name"); //初始化数组内容
rowData[count][1]=Integer.toString(rs.getInt("age"));
rowData[count][2]=rs.getString("sex");
rowData[count][3]=rs.getString("email");
count++;
}
con.close(); //关闭连接
}
catch(Exception ex){
ex.printStackTrace(); //输出出错信息
}
Container container=getContentPane(); //获取窗口容器
//container.setLayout(null);
container.add(ok);container.add(canel); ok.setBounds(10,120,70,20);
canel.setBounds(100,120,70,20);
table=new JTable(rowData,columnNames); //实例化表格
table.getColumn("年龄").setMaxWidth(25); //设置行宽
container.add(new JScrollPane(table),BorderLayout.CENTER); //增加组件
setSize(300,200); //设置窗口尺寸
setVisible(true); //设置窗口可视
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
}
public static void main(String[] args){
new DisplayDemo();
}
}
-----------------
这是其中一个例子 你照着上面做就可以了
这种系统应该网上很多吧
绛旓細import javax.swing.table.*;//import java.awt.event.*;public class DisplayDemo extends JFrame //implements { // private String dbURL="jdbc:microsoft:sqlserver://202.115.26.181:1433"; // 鏁版嵁搴鏍囪瘑鍚 private String user="devon"; // 鏁版嵁搴撶敤鎴 private String password="book";/...
绛旓細public static void findInfo(String filePath) throws IOException { //鎶婁箣鍓嶅瓨鍏ュ埌鏁版嵁鐨勬枃浠讹紝璇诲彇鍒伴泦鍚堜腑鏉ャ侫rrayList<Student> list = new ArrayList<Student>();readData(list,filePath);//閬嶅巻闆嗗悎 for(int i=0;i<list.size();i++) { Student stu = list.get(i);System.out....
绛旓細闅忕潃淇℃伅鍖栨椂浠e瀛︽牎绠$悊鏁堢巼鐨勯渶姹傛彁鍗囷紝鏈爺绌舵棬鍦ㄥ紑鍙涓涓鐜颁唬涓旈珮鏁堢殑鏍″洯鏃ュ父绠$悊绯荤粺銆傜郴缁熺殑鏍稿績鐩爣鏄暣鍚堟暀鍔°佸鏍′俊鎭鐞嗗強鐤儏闃叉帶缁熻锛屽悓鏃朵紭鍖栧鏍″悎浣滃钩鍙帮紝浠ユ彁鍗囨暀甯堝伐浣滄晥鐜囧拰瀹堕暱鍙備笌搴︺傜郴缁熷皢鍒╃敤Java鎶鏈紝缁撳悎MySQL鏁版嵁搴锛屽疄鐜颁互涓嬪姛鑳斤細鐢ㄦ埛娉ㄥ唽銆佺櫥褰曘佷釜浜轰俊鎭鐞 鐤儏淇℃伅鐨勫疄鏃...
绛旓細鎮ㄥソ锛屾彁闂咃細 缁欎綘涓涓鏌ヨaccess鏁版嵁搴锛岀劧鍚庡埌澶勫埌xls鐨勪緥瀛愬惂銆傘傘//涓嬮潰鏄唬鐮乮mport java.io.FileWriter;import java.io.IOException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement; public class...
绛旓細绠$悊鏁版嵁搴浜嬪姟 • 榛樿鎯呭喌涓,JDBC灏嗕竴鏉℃暟鎹簱璇彞瑙嗕负涓涓瀹屾暣鐨勪簨鍔°傚彲浠ュ叧鎺夐粯璁や簨鍔$鐞: public void setAutoCommit(Boolean autoCommit) throws SQLException; 灏哸utoCommit鐨勫艰缃负false,灏卞叧鎺変簡鑷姩浜嬪姟绠$悊妯″紡• 鍦ㄦ墽琛屽畬浜嬪姟鍚,搴旀彁浜や簨鍔: public void commit() throws SQLException;• 鍙互鍙栨秷...
绛旓細1銆佹敹閾剁郴缁熸妧鏈夊瀷 鏀堕摱绯荤粺鐢变簬娑夊強鍒扮晫闈㈠紑鍙戯紝骞朵笖鏄敹閾舵満鐣岄潰锛屽彲浠ヤ娇鐢╯wing妗嗘灦鍜宺estful鍘诲紑鍙戠晫闈紝鏁版嵁搴鍙互浣跨敤db2鎴栬卲ostgresql銆2銆佸悗绔绠$悊绯荤粺寮鍙 鍚庡彴鍓嶇锛氬彲浠ヤ娇鐢‥S鎴栬卬odeJS锛屽墠鍚庣鍒嗙锛屼娇鐢╮estful鏉ヨ繘琛岃闂悗绔湇鍔$郴缁熴傚悗绔湇鍔$郴缁燂細鐜板湪涓鑸娇鐢╯pringMVC鎴栬卻pringboot浣滀负妗嗘灦锛...
绛旓細import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao { // 鏁版嵁搴椹卞姩 String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//url String url ...
绛旓細浣跨敤鍒扮殑鎶鏈紝鏁扮粍锛屽彲浠ワ紝姣斿鍥句功绠$悊绯荤粺浣犲瓨鍥句功锛屽彲浠ョ敤Book[]杩欑鐨勬暟缁勫綋鐒跺墠鎻愪綘鏈塀ook瀹炰綋绫伙紝鎴栬呯敤List绛夐泦鍚堬紝鍐嶉珮绔偣鐨勶紙褰撶劧浣犱笉鐢╦dbc杩鏁版嵁搴锛屾瘯绔熻鐢ㄦ暟缁勶紝浣嗘槸鏁扮粍灏辩浉褰撲簬鏈绠鍗曠殑鍐呭瓨鏁版嵁搴擄級浣犲彲浠ヤ娇鐢╞erkleydb绛夈傝繖鏄鐨勫瓨鍌ㄣ涓涓Book瀹炰綋鐨勪竴涓釜灞炴ц鐢ㄦ埛杈撳叆浜嗭紝鐒跺悗...
绛旓細鐒跺悗灏辨槸鎶婃墍鏈JAVA浠g爜宓屽叆鍒癑SP涓潵鍐欙紝杩欐牱鏄渶鐪佷簨鐨勩備篃鍙互浣跨敤servlet+JSP鏉ュ啓锛屼笉杩囩浉瀵圭殑灏辫澶氬涓鐐圭煡璇嗐備笉杩囪繖绉嶅彧鑳界畻鏄垵绾т竴浜涚殑 鐜板湪娴佽SSH妗嗘灦 锛屼綘涔熷彲浠ュ涔犺繘琛屽簲鐢ㄣ傛仼鏈鍩烘湰鐨勪唬鐮侊紝浣犲彲浠ュ幓鍊熶竴浜涘疄渚嬩功锛屽弬鑰冪殑鍋涓涓锛岃繖鏍蜂篃姣旇緝閫熸垚銆傛棦鐒朵綘鏈java鍩虹鐪嬫噦涓浜涗篃涓嶆槸寰堝洶闅撅紝...
绛旓細鍥句功棣嗗熼槄绠$悊绯荤粺锛JAVA璁捐瀹炵幇姒傝堪杩欎釜绯荤粺鏄涓涓缁煎悎鐨凧AVA+Vue+SpringBoot+MySQL鏋勫缓鐨勫浘涔﹀熼槄绠$悊绯荤粺锛屾兜鐩栧涓ā鍧楋紝濡傚浘涔︽。妗堛佸浘涔﹂瀹氥佸浘涔﹁瘎璁哄拰鍥句功鏂伴椈銆傚畠杩樺叿澶囩敤鎴枫侀儴闂ㄣ佽鑹层佽彍鍗曘佹棩蹇椼鏁版嵁瀛楀吀鍜屾枃浠剁鐞嗙瓑鍩虹鍔熻兘锛岄噰鐢ㄨ鑹茶闂帶鍒讹紝瀵圭鐞嗗憳鍜屽鐢熺敤鎴锋彁渚涚簿缁嗙殑鏉冮檺绠$悊銆傜郴缁...