jdbc

zdf312 2009-03-27 05:00:21
public class Base {

/**
* @param args
*/
public static void main(String[] args) {
static void template() throws Exception {
String url="jdbc:mysql://localhost:3306/jsbc";
String user="root";
String password="admin";
Connection conn=null;
Statement st=null;
ResultSet rSet=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url,user,password);
st=conn.createStatement();
rSet=st.executeQuery("select * from user");
while(rSet.next()){
System.out.println(rSet.getObject(1)+"\t"+rSet.getObject(2)
+"\t"+rSet.getObject(3)+"\t");
}
}finally{
try{
if(rSet!=null)
rSet.close();
}finally{
try{
if(st!=null)
st.close();
}finally{
if(conn!=null)
conn.close();
}
}
}
}
}
请问这段代码哪里出问题啦,我拿myeclipse7.0运行老是出错,提示‘{’有问题,不懂。
...全文
107 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jumpheightway 2009-03-29
  • 打赏
  • 举报
回复
方法内部还能够定义方法吗
你才搞笑呢
不知道从那里来的语法
sirtener 2009-03-28
  • 打赏
  • 举报
回复
LZ,注意自己的编码规范,这样就可以避免不必要的错误
酒浪子 2009-03-28
  • 打赏
  • 举报
回复
main方法中不能定义方法!
fengqiaoyebo2008 2009-03-28
  • 打赏
  • 举报
回复
lz应该把格式排好,就很容易看出来了。向2楼学习。
fanyuanwaifdl 2009-03-28
  • 打赏
  • 举报
回复
2楼正解
Looking_Glass 2009-03-28
  • 打赏
  • 举报
回复
呦!路过!这个错误!
skhlaila 2009-03-28
  • 打赏
  • 举报
回复
软件技术群:83076723 欢迎加入!
Study_Work_2009 2009-03-28
  • 打赏
  • 举报
回复
up
vampireallen 2009-03-27
  • 打赏
  • 举报
回复
能告诉我你在main方法里还定义了个方法是怎么想的吗?把这个改掉之后,在在最后加个大括号就行了
makani 2009-03-27
  • 打赏
  • 举报
回复
我觉得平时编程的时候还是要多注意一下代码规范,要不然像这种问题还是会有的,并且还是比较小的问题,如果这样的问题太频繁的话,会很影响我们编程的
zhangdouzd 2009-03-27
  • 打赏
  • 举报
回复
2楼的正确没错,不过我想问一下,LZ的到底错在哪里了?
w111222j 2009-03-27
  • 打赏
  • 举报
回复
进来顶一下.楼上的正确吧.呵可

这种错误还是容易找的啊
ohmydog1 2009-03-27
  • 打赏
  • 举报
回复

public class Base{

/**
* @param args
*/ static void template() throws Exception {
String url="jdbc:mysql://localhost:3306/jsbc";
String user="root";
String password="admin";
Connection conn=null;
Statement st=null;
ResultSet rSet=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url,user,password);
st=conn.createStatement();
rSet=st.executeQuery("select * from user");
while(rSet.next()){
System.out.println(rSet.getObject(1)+"\t"+rSet.getObject(2)
+"\t"+rSet.getObject(3)+"\t");
}
}
finally{
try{
if(rSet!=null)
rSet.close();
}finally{
try{
if(st!=null)
st.close();
}finally{
if(conn!=null)
conn.close();
}
}
}
}
public static void main(String[] args) throws Exception{
template();
}
}
vampireallen 2009-03-27
  • 打赏
  • 举报
回复
少了
public class Base {
这一层的大括号

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧