java编写数据库查询执行器的问题?求帮忙看下
代码如下,调试了很久,没调好,帮忙看下,,,JAVA初学者,,谢谢了!明天要交这个作业,急死了,,,
package quaryExcutor;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import
java.sql.SQLException;
import java.sql.Statement;//用于在已经建立数据库连接的基础上,向数据库发送要执行的SQL语句。
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class go extends JFrame
{
private static final long serialVersionUID = 1L;
private JLabel l1;
private JLabel l2;
private JTextField sql;
private JButton ex;
private JFrame jf;
public go()
{
jf.setTitle("SQL查询执行器");
jf.setSize(500, 150);
jf.setVisible(true);
jf.setLocationRelativeTo(null);///使窗口显示到中间
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//使用 System exit 方法退出应用程序
l1=new JLabel("请输入要执行的SQL语句:");
l2=new JLabel("执行结果");
sql=new JTextField();
sql.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
}
}
});
ex=new JButton("执行");
ex.addActionListener(new exlistener());
JPanel inputpanel=new JPanel();
JPanel buttonpanel=new JPanel();
inputpanel.setLayout(new BoxLayout(inputpanel,BoxLayout.Y_AXIS));//垂直排列
buttonpanel.setLayout(new FlowLayout());//居中对齐
inputpanel.add(l1);
inputpanel.add(sql);
inputpanel.add(l2);
buttonpanel.add(ex);
this.getContentPane().add(inputpanel,BorderLayout.NORTH);
this.getContentPane().add(buttonpanel,BorderLayout.SOUTH);
}
}
try {
Connection con=DriverManager.getConnection("user/db/schema");
Statement stmt=con.createStatement();
String SQL=sql.getText();
stmt.execute(SQL);
l2.setText("执行成功!");//将l2上面的文字设置为"执行成功!"