Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MySQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助:基于MYSQL的JAVA用户界面查询程序中的错误
moonlake





发贴: 1
积分: 0
于 2006-06-06 12:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import com.mysql.jdbc.Driver;

class MainFrame extends JFrame implements ActionLister{
JPanel contentPane;
BorderLayout borderLayout1=new BorderLayout(5,10);
Label prompt;
Choice firstname;
Button querybutton;
TextArea result;

pubilc MainFrame(){
contentPane=(JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setTitle("DBQuery");
addWindowListener(new WindowAdapter(){
pubilc void windowClosing(WindowEvent e){
System.exit(0);
}
});
prompt=new Label("firstname");
firstname=new Choice();
querybutton=new Button("Query");
result=new TextArea();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost/test?user=root&password=147";
String ls_1="select firstname from employee";

Connection con=DriverManager.getConnection(url);
Stmt=con.createStatement();
while(rs.next()){
firstname.add(rs.getString(1));

}
rs.close();
stmt.close();
con.close();
}
catch(SQLException sple){}
catch(Exception e){}
contentPane.add(prompt,BorderLayout.WEST);
contentPane.add(firstname,BorderLayout.CENTER);
contentPane.add(querybutton,BorderLayout.EAST);
contentPane.add(result,BorderLayout.SOUTH);
querybutton.addActionListener(this);

}

pubilc void actionPerformed(ActionEvent e){
if(e.getSource()==querybutton){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();

String url="jdbc:mysql://localhost/test?user=root&password=147";
String queryfirstname=firstname.getSelectedItem();
String ls_1="select*from employee"+"where firstname='"+queryfirstname+"'";
Connection con=DriverManager.getConnection(url,user,password);
Statement Stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(ls_1);
result.setText("");
while(re.next()){
String msg=rs.getString(1)+"|"+
rs.getString(2)+"|"+
rs.getString(3)+"|"+
rs.getString(4)+"|"+
rs.getString(5);
result.append(msg);

}
rs.close();
stmt.close();
con.close();

}
catch(SQLException sqle){}
catch(Exception exce){}

}
}

public static void main(String args[]){
MainFrame frame=new MainFrame();
frame.resize(400,300);
frame.show();
}
}

编译后有错:
--------------------Configuration: <Default>--------------------
C:\Documents and Settings\Administrator\桌面\MainFrame.java:21: <identifier> expected
pubilc void windowClosing(WindowEvent e){
^
C:\Documents and Settings\Administrator\桌面\MainFrame.java:24: ';' expected
});
^
C:\Documents and Settings\Administrator\桌面\MainFrame.java:54: <identifier> expected
pubilc void actionPerformed(ActionEvent e){
^
C:\Documents and Settings\Administrator\桌面\MainFrame.java:91: ';' expected
}
^
4 errors

Process completed.
用的是JCreater,Mysql数据库连接成功。可是这些错误真的莫明其妙,我刚学mysql大家帮帮忙,看看。


why edited on 2006-06-06 18:11


作者 Re:求助:基于MYSQL的JAVA用户界面查询程序中的错误 [Re:moonlake]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-06-06 18:21 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ActionLister --> ActionListener



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923