用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

jdbc

2016-08-02 作者: 云代码会员举报

[java]代码库

package JDBC;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class JDBC extends JFrame{

	//用户名 账号登入 private static final String URL = "jdbc:sqlserver://挚爱:1433;user=sa;password=1234;DatabaseName=HuffmanTree";
	//服务器自动登入 private static final String URL = "jdbc:sqlserver://挚爱:1433;integrated Security=true;DatabaseName=HuffmanTree";
	private static final String URL = "jdbc:sqlserver://挚爱:1433;DatabaseName=HuffmanTree";
	private static final String USERNAME = "sa";
	private static final String PASSWORD = "1234";
	
	static {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace(); 
		}
	}

	public static void main(String[] args) {
		JDBC frame = new JDBC();
		frame.setVisible(true);

	}
	public JDBC(){
		super();
		setTitle("Huffman编码译码展示");
		setBounds(100,100,480,420);
		getContentPane().setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		try {
			Connection conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
			Statement statement = conn.createStatement();        //静态
			
			
			//----------------------------------------------------------------------------------------
			
			
			
			JPanel panel1 = new JPanel(); 						//创建label“请输入编码内容 ”
			//panel1.setLayout(new FlowLayout());
			final JLabel label = new JLabel();
			label.setText("请输入编码内容:");
			panel1.add(label);
			
			JTextField textField = new JTextField();
			textField.setColumns(20);
			panel1.add(textField);	

			
			JButton button = new JButton();
			button.setText("转换");
			panel1.add(button);
			
			
			panel1.setBounds(0, 0, 450, 35);
			getContentPane().add(panel1);

			
			
			//-----------------------------------------------------------------------------------------
			
			
			
			JPanel panel2 = new JPanel(); 						//创建数据库表
            BorderLayout borderLayout2 = new BorderLayout();
            panel2.setLayout(borderLayout2); 
            final JLabel label1 = new JLabel();
			label1.setText("Huffman树的结点数组:\n");
			panel2.add(label1,BorderLayout.NORTH);
            JScrollPane jScrollPane1 = new JScrollPane();
            panel2.add(jScrollPane1);
            panel2.add(jScrollPane1,BorderLayout.CENTER);
            Object[][] rowData = {
                    {"1001", "李汉", "软件部", new Double(3000)},
                    {"1002", "朱泽", "软件部", new Double(3100)},
                    {"1003", "刘宇", "经理部", new Double(3000)},
                    {"1004", "刘宇", "经理部", new Double(3000)},
                    {"1005", "刘宇", "经理部", new Double(3000)},
                    {"1006", "刘宇", "经理部", new Double(3000)},
                    {"1007", "刘宇", "经理部", new Double(3000)},
                    {"1008", "刘宇", "经理部", new Double(3000)},
		    };
			Object[] columnsName = {"data", "parent", "left", "right"};
			DefaultTableModel dtm = new DefaultTableModel(rowData, columnsName);
			JTable jTable1 = new JTable(dtm);
            jScrollPane1.getViewport().add(jTable1);
            panel2.setBounds(2,50,460,190);
            getContentPane().add(panel2);
            
            
           //----------------------------------------------------------------------------------------------
            
            
			//String sql = "select * from Table_1";
			//ResultSet rs = statement.executeQuery(sql); //
            
            
		//---------------------------------------------------------------------------------------------------
            
            
            
            
			statement.close();
			conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}	
	}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...