Java数据库连接转换Access->SQLServer
本人新手,书上好像都是Access,现在想把Access转化为SQLServer,在网上找到一些资料,但是没有成功。希望各位大神能够帮助一下,最好能把关于SQLServer链接详细说一下,谢谢了!!!程序代码:
import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class fwin extends JFrame implements ActionListener { JTable table; JButton b1,b2,b3,b4; Object a[][]; Connection con; Statement sql; ResultSet rs; Object columnName[] = {"学号","姓名","数学","英语"}; fwin(){ super("数据库查询"); a = new Object[60][4]; table = new JTable(a,columnName); setSize(500,500); b1 = new JButton("浏览表"); b2 = new JButton("排序"); b3 = new JButton("查询"); b4 = new JButton("退出"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); Container con = getContentPane(); con.setLayout(new FlowLayout()); con.add(b1); con.add(b2); con.add(b3); con.add(b4); Container container = getContentPane(); container.add(new JScrollPane(table),BorderLayout.CENTER); setVisible(true); validate(); removeWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } int i=0; public void actionPerformed1(ActionEvent ev) { if(ev.getSource() == b1) { while(i>=0) { a[i][0]=""; a[i][1]=""; a[i][2]=""; a[i][3]=""; i--; } i=0; try{ Class.forName("sun.jdbc.odbc.JdbcOdacDriver"); } catch(ClassNotFoundException e) {} try{ con = DriverManager.getConnection("jdbc:odbc:abc","",""); sql = con.createStatement(); rs = sql.executeQuery("Selsec*From biao"); while(rs.next()){ String number = rs.getString(i); String name = rs.getString(2); int math = rs.getInt("数学"); int eng = rs.getInt("英语"); a[i][0] = number; a[i][1] = name; a[i][2] = String.valueOf(math); a[i][3] = String.valueOf(eng); i++; } con.close(); repaint(); }catch(SQLException el){}; } else if(ev.getSource() == b2) { while(i>=0) { a[i][0]=""; a[i][1]=""; a[i][2]=""; a[i][3]=""; i--; } i=0; try{ Class.forName("sun.jdbc.odbc.JdbcOdacDriver"); } catch(ClassNotFoundException e) {} try{ con = DriverManager.getConnection("jdbc:odbc:abc","",""); sql = con.createStatement(); rs = sql.executeQuery("Selsec*From biao"); while(rs.next()){ String number = rs.getString(i); String name = rs.getString(2); int math = rs.getInt("数学"); int eng = rs.getInt("英语"); a[i][0] = number; a[i][1] = name; a[i][2] = String.valueOf(math); a[i][3] = String.valueOf(eng); i++; } con.close(); repaint(); }catch(SQLException el){}; } else if(ev.getSource()==b3) { while(i>=0) { a[i][0]=""; a[i][1]=""; a[i][2]=""; a[i][3]=""; i--; } i=0; try{ Class.forName("sun.jdbc.odbc.JdbcOdacDriver"); } catch(ClassNotFoundException e) {} try{ con = DriverManager.getConnection("jdbc:odbc:abc","",""); sql = con.createStatement(); rs = sql.executeQuery("Selsec*From biao"); while(rs.next()){ String number = rs.getString(i); String name = rs.getString(2); int math = rs.getInt("数学"); int eng = rs.getInt("英语"); a[i][0] = number; a[i][1] = name; a[i][2] = String.valueOf(math); a[i][3] = String.valueOf(eng); i++; } con.close(); repaint(); }catch(SQLException el){}; } else if(ev.getSource() == b4) dispose(); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } } class query{ public static void main(String[] args) { new fwin(); } }