先下载MSSQLSERVER的驱动程序,然后,程序如下import java.io.*;
import java.sql.*;
class bookquery
{
public static void main(String args[])
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");}
catch(ClassNotFoundException ce)
{ System.out.println("SQLException"+ce.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=database;user=sa;password=");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from booktab");
while(rs.next())
{
System.out.println(
"书号" +rs.getInt(1)+'\t'+
"书名" +rs.getString(2)+'\t'+
"作者" +rs.getString(3)+'\t'+
"单价" +rs.getFloat(4));
}
stmt.close();
con.close();
}
catch(SQLException e)
{ System.out.println("SQLException"+e.getMessage());}
}
}
import java.sql.*;
class bookquery
{
public static void main(String args[])
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");}
catch(ClassNotFoundException ce)
{ System.out.println("SQLException"+ce.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=database;user=sa;password=");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from booktab");
while(rs.next())
{
System.out.println(
"书号" +rs.getInt(1)+'\t'+
"书名" +rs.getString(2)+'\t'+
"作者" +rs.getString(3)+'\t'+
"单价" +rs.getFloat(4));
}
stmt.close();
con.close();
}
catch(SQLException e)
{ System.out.println("SQLException"+e.getMessage());}
}
}
解决方案 »
- 请教如何统计快速排序选择了多少次基准值(pivot)?
- java有根据点画直线的函数吗?
- 帮我设置下环境变量classpath和Path设置
- 请写出下面代码的多次类型转化后的结果
- 请教把JAVA代码转换为VC代码需要注意哪些问题?
- 使用jacob实现word替换时,为什么不能连续替换?!代码如下!请大侠指点!
- ****高手请进,如何实现选择性接受键盘事件?****
- 一个起步问题, 简单。
- 在Java里,如何去掉文件的只读属性.File.setReadOnly()可以设置,但如何去除呢?
- 紧急求救,地地道道的菜鸟!
- JInternalFrame关闭问题
- 请问setAttribute这个方法是作什么用的?谢谢。
但是报错了,如下
SQLExceptioncom.microsoft.jdbc.sqlserver.SQLServerDriver
SQLExceptionNo suitable driver