Java连接数据库增删改查(精)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Java连接sql2000数据库增删改查功能

学院:仲恺农业工程学院姓名:陈伟团专业:计算机科学与技术班级:084班

1. 数据库连接

package edu;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class DBConnection {

public static Connection getConnection({

Connection conn = null;

String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String url =

"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shop"; String username = "sa";

String password = "sa";

try {

Class.forName(driver;

conn = DriverManager.getConnection(url,username,password;

} catch (ClassNotFoundException e {

e.printStackTrace(;

} catch (SQLException e {

e.printStackTrace(;

}

return conn;

}

2. 生成get set方法

package edu;

public class Country {

private String name;

private String region;

private String area;

private String population;

private String gdp;

public String getName( {

return name;

}

public void setName(String name {

= name;

}

public String getRegion( {

return region;

}

public void setRegion(String region {

this.region = region;

}

public String getArea( {

return area;

}

public void setArea(String area {

this.area = area;

}

public String getPopulation( {

return population;

}

public void setPopulation(String population { this.population = population;

}

public String getGdp( {

return gdp;

}

public void setGdp(String gdp {

this.gdp = gdp;

}

}

3实现方法

package edu;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.List;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

import javax.swing.SwingUtilities;

public class CountryInfoGui implements ActionListener { private JFrame jFrame;

private JPanel jContentPane;

private JLabel lblName = null;

private JTextField tfName = null;

private JLabel lblRegion = null;

private JComboBox cbRegion = null;

private JLabel lblArea = null;

private JTextField tfArea = null;

private JLabel lblPopu = null;

相关文档
最新文档