把sql查到的表显示到文本区,新手啊不会,求指导
帮忙改下
public class txt extends JFrame {
private static final String FILE_NAME ="C:\\ab.txt";//文件名可改
JButton b1;//按钮
JTextArea txt1;//文本区
public txt(){
		this.setTitle("txt文件载入");
		b1=new JButton("点击载入文件");
		b1.addActionListener(new ActionListener(){			
		//发生操作事件时,调用该对象的 actionPerformed 方法。
			 public void actionPerformed(ActionEvent e) {
	                System.out.println(e.getActionCommand());
	                loadFile(FILE_NAME);
	            }
});		
		this.add(b1,BorderLayout.SOUTH);//按钮位置为下中间
		txt1=new JTextArea();
		this.add(txt1,BorderLayout.CENTER);//文本居中		
	}
	private  void loadFile(String filename){
		Scanner sc=null;//文本扫描器
		try{
			sc=new Scanner(new File(filename));
			txt1.setText("");
			// 如果在此扫描器的输入中存在另一行
			while(sc.hasNextLine()){
				txt1.append(sc.nextLine());			
			txt1.append("\n");
			}			
		}
		//没有找到文件异常监测
		catch(FileNotFoundException e){
			e.printStackTrace();			
		}
		//异常监测
		finally{
			if(sc!=null)
				sc.close();			
		}
	}
public static void main(String[] args){
	txt wnd=new txt();
	wnd.setSize(600,500);//窗口大小
	wnd.setVisible(true);//设置窗口可见	
     }
}
下面试我连接数据库成功的代码
package pkg;
import java.sql.*;
public class Main {	
	public static void main(String[]args)
	{		
	String	driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";		
	String  dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=test";
	String userName="sa";
	String userPwd="123456";
	try{
		Class.forName(driverName);
		Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
		System.out.println("连接成功");				
	}
	catch(Exception e){
		 e.printStackTrace();		
		System.out.println("连接失败");		
	}
	}
}
------解决方案--------------------
你把你的SQL语句找出来,放到查询分析器运行就可以了啊
------解决方案--------------------
我没找到你的SQL语句。
你指的文本区是哪儿的文本区啊??
你是想把查询的结果遍历到你的程序上?还是想在哪儿展示???
------解决方案--------------------
看看ado相关资料。
------解决方案--------------------
楼主:基于你的问题的解答:
1。点击按钮时显示txt文件,那么你的界面所用的控件应该是文件框。
2。现在你想显示数据库的表,那么你需要把控件改成dataview或其它数据显示控件。
那么这样你点击它就把数据显示出来了。如果楼主还想把数据显示在文本框中,也是可以的,你可以把语句改成print试试,也可以先转换成文本格式,然后再显示出来。
方法比较多,希望楼主根据自己的实际情况修改程序。
预祝楼主成功。