主题:[讨论]java连接数据库出现的问题
import java.sql.*;
public class Text
{
public static void main(String args[])
{
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("ttt.Jdbc.Odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{ System.out.println(""+e);
}
try{ con=DriverManager.getConnection("jdbc:odbc:student");
sql=con.createStatement();
rs=sql.executeQuery("SELECT *FROM students");
while(rs.next())
{
String number=rs.getString(1);
String name=rs.getString(2);
System.out.println("学号"+number);
System.out.println("姓名"+name);
}
con.close();
}
catch(SQLException e)
{
System.out.println(e);
}
}
}
编译可以通过,但是无法连接到数据库。。。具体的显示如下
java.lang.ClassNotFoundException: ttt.Jdbc.Odbc.JdbcOdbcDriver
java.sql.SQLException: No data found
请各位帮助看一下。。谢谢
public class Text
{
public static void main(String args[])
{
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("ttt.Jdbc.Odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{ System.out.println(""+e);
}
try{ con=DriverManager.getConnection("jdbc:odbc:student");
sql=con.createStatement();
rs=sql.executeQuery("SELECT *FROM students");
while(rs.next())
{
String number=rs.getString(1);
String name=rs.getString(2);
System.out.println("学号"+number);
System.out.println("姓名"+name);
}
con.close();
}
catch(SQLException e)
{
System.out.println(e);
}
}
}
编译可以通过,但是无法连接到数据库。。。具体的显示如下
java.lang.ClassNotFoundException: ttt.Jdbc.Odbc.JdbcOdbcDriver
java.sql.SQLException: No data found
请各位帮助看一下。。谢谢