当前位置: 技术问答>java相关
数据库的问题
来源: 互联网 发布时间:2015-04-15
本文导语: 小弟初学java 不知下面这段代码为何同不过 望大家帮忙 小弟先谢了 代码如下 import java.sql.*; import java.lang.*; public class Databaseapp{ public static void main(String args[]){ Class.forName("sun.jdbc.odb...
小弟初学java 不知下面这段代码为何同不过 望大家帮忙
小弟先谢了
代码如下
import java.sql.*;
import java.lang.*;
public class Databaseapp{
public static void main(String args[]){
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myconnection=DriverManager.getConnection("jdbc:odbc:estdb","sa","");
Statement mystatement=myconnection.createStatement();
ResultSet query=mystatement.executeQuery("select * from est_info");
while (query.next())
System.out.println(query.getString("est_id")+query.getString("est_name"));
}
}
小弟先谢了
代码如下
import java.sql.*;
import java.lang.*;
public class Databaseapp{
public static void main(String args[]){
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myconnection=DriverManager.getConnection("jdbc:odbc:estdb","sa","");
Statement mystatement=myconnection.createStatement();
ResultSet query=mystatement.executeQuery("select * from est_info");
while (query.next())
System.out.println(query.getString("est_id")+query.getString("est_name"));
}
}
|
用try{...}catch{....}捕作异常。
import java.sql.*;
import java.lang.*;
public class Databaseapp{
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myconnection=DriverManager.getConnection("jdbc:odbc:estdb","sa","");
Statement mystatement=myconnection.createStatement();
ResultSet query=mystatement.executeQuery("select * from est_info");
while (query.next())
System.out.println(query.getString("est_id")+query.getString("est_name"));
}catch(Exception e){
System.out.println("Error:"+e.toString());
}
}
}
import java.sql.*;
import java.lang.*;
public class Databaseapp{
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myconnection=DriverManager.getConnection("jdbc:odbc:estdb","sa","");
Statement mystatement=myconnection.createStatement();
ResultSet query=mystatement.executeQuery("select * from est_info");
while (query.next())
System.out.println(query.getString("est_id")+query.getString("est_name"));
}catch(Exception e){
System.out.println("Error:"+e.toString());
}
}
}