import java.sql.*;
import java.io.*;
public class DataBase {
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException e)
{
System.out.println("got a error, as following");
e.printStackTrace();
}
Connection conn=DriverManager.getConnectio("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bossfish","sa","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from book");
while(rs.next())
{
System.out.println(rs.getString("computer science"));
}
rs.close();
stmt.close();
conn.close();
} }
--------------------------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException at com.wgh.DataBase.main(DataBase.java:24)搞了老半天不晓得错在哪里,郁闷中...
import java.io.*;
public class DataBase {
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException e)
{
System.out.println("got a error, as following");
e.printStackTrace();
}
Connection conn=DriverManager.getConnectio("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bossfish","sa","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from book");
while(rs.next())
{
System.out.println(rs.getString("computer science"));
}
rs.close();
stmt.close();
conn.close();
} }
--------------------------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException at com.wgh.DataBase.main(DataBase.java:24)搞了老半天不晓得错在哪里,郁闷中...
解决方案 »
- Arraylist 调用 isempty 与size抛出空指针异常
- 紧急求助,用java如何将一个带有图片的excel文件转换成pdf文件?
- 急,不用到SERVLET,只是给你一个URL地址,可以下载文件到本地吗?
- 是不是现在JAVA也可以写病毒了?
- 新手 等帮忙
- 我想用java访问sql server2000,怎么不行啊?请赐教。
- 谁告诉俺个能把classcode转化成机器码的工具,就是把java程序作成*.exe,谢谢
- 怎么分别获取当前的年,月,日
- 什么时候用自定义事件
- 你们好,我是一位新手,有件事想请教各位java高手
- java 中的线程是一种对象,那 Thread main为什么不是??
- LIST调用问题
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
}catch(ClassNotFoundException e)
{
System.out.println("got a error, as following");
e.printStackTrace();
}
Connection conn=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433;DatabaseName=bossfish","sa"," ");
Statement stmt=conn.createStatement();
System.out.println(conn);
stmt.close();
conn.close();
}
运行结果:
net.sourceforge.jtds.jdbc.ConnectionJDBC3@1050e1f
最后几句大妈都要抛异常的,是非运行时异常,一定要捕获或抛出的try{
rs.close();
stmt.close();
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
public static void main(String[] args) throwx Exception进行测试好了,先专心在业务逻辑上。
所有的SQL 操作,必须外面加上 SQLException 的 catch, 具体的参考4楼的那位。
在24行
估计是rs取值的问题。
你用的是select * from *** 那么必须把所有的值全部都用一遍。
关闭连接是也要抛异常呀。