java连接数据库中的事先写好的数据库文件放在那个文件夹啊?
package jdbc;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.sql.*;
class Window extends Frame implements ActionListener
{
TextArea text;
Panel panel;
TextField xingming;
Button button1,button2;
Window()
{
super("成绩查询");
setLayout(new BorderLayout());
setBackground(Color.cyan);
setBounds(150,150,300,120);
setVisible(true);
text=new TextArea();
button1=new Button("确定");
button2=new Button("查询所有人的成绩");
xingming=new TextField(16);
panel=new Panel();
panel.add(new Label("输入被查询的学生的姓名:"));
panel.add(xingming);
panel.add(button1);
add("North",panel);
add(text,"Center");
add(button2,"South");
text.setEditable(false);
text.setBackground(Color.pink);
button1.addActionListener(this);
button2.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
text.setText("查询结果:"+'\n');
try{ Liststudent1(); }
catch(SQLException ee){ }
}
else if(e.getSource()==button2)
{
text.setText("查询的结果"+'\n');
try{ Liststudent2(); }
catch(SQLException ee){ }
}
}
public void Liststudent1() throws SQLException
{
String name;
int math,english,physics,sum;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
catch(ClassNotFoundException e){ }
Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT*FROM chengjibiao");
while(rs.next())
{
name=rs.getString("姓名");
math=rs.getInt("数学");
physics=rs.getInt("物理");
english=rs.getInt("英语");
sum=english+math+physics;
if((name.trim()).equals(xingming.getText().trim()))
{
text.append("***"+"\n"+name+"的成绩:"+"\n"+"数学:"+math+
"\t英语:"+english+"\t物理:"+physics+"\t总分:"+sum+'\n');
}
}
if((text.getText().trim()).equals("查询结果:"))
text.setText("没有此人的成绩");
}
public void Liststudent2() throws SQLException
{
String name;
int math,english,physics,sum;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
catch(ClassNotFoundException e){ }
Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT*FROM chengjibiao");
while(rs.next())
{
name=rs.getString("姓名");
math=rs.getInt("数学");
physics=rs.getInt("物理");
english=rs.getInt("英语");
sum=english+math+physics;
text.append("***"+"\n"+name+"的成绩:"+"\n"+"数学:"+math+
"英语:"+english+"物理:"+physics+"总分:"+sum+'\n');
}
}
}
public class jdbc
{
public static void main(String args[])
{
Window window=new Window();
window.pack();
}
}
[解决办法]
一般是放在src目录下。另外楼主的代码能运行机制吗?好好看下JDBC
[解决办法]
最好放在你的工程根路径 访问方便点
[解决办法]
一般放在工程下面哪儿都行,只是需要导入和不导入的区别而已,不过楼主的代码貌似并没有把jdbc部分写出去啊,连接部分应该写在工具类里面比较好,像这样写的话和直接写在该类里面差不多了,并没有完全避免代码的重用