关于转数据库的问题,急
旋转的转头 2008-02-26 09:47:15 package com.logistic.data;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.sql.Date;
//import java.text.SimpleDateFormat;
/**
****************************************************
*类名称: Db<br>
*类功能: 数据库操作 <br>
*创建: ckjava<br>
****************************************************
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DataConnect {
private Connection con;
private Statement stmt;
private ResultSet rs;
private PreparedStatement pstmt;
public static int error=0;
/***************************************************
*函数名称: getCon()<br>
*函数功能: 获取数据库连接<br>
*返回值: 无<br>
*参数说明: 无<br>
*创建: ckjava
****************************************************/
public static synchronized Connection getCon()throws Exception{
Context ctx;
DataSource ds;
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/DBPool");
if(ds==null){
System.err.println();
System.err.println("数据连接打开+"+(++error));
}
return ds.getConnection();
}catch(SQLException e){
System.out.print(e);
throw e;
}
catch(NamingException e){
System.out.print(e);
throw e;
}
}
这个是连接MYSQL的bean,我想把它转换成连接sql server的bean,如下:
ackage com.logistic.data;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.sql.Date;
//import java.text.SimpleDateFormat;
/**
****************************************************
*类名称: Db<br>
*类功能: 数据库操作 <br>
*创建: ckjava<br>
****************************************************
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DataConnect {
private Connection con;
private Statement stmt;
private ResultSet rs;
private PreparedStatement pstmt;
public static int error=0;
/***************************************************
*函数名称: getCon()<br>
*函数功能: 获取数据库连接<br>
*返回值: 无<br>
*参数说明: 无<br>
*创建: ckjava
****************************************************/
public static synchronized Connection getCon()throws Exception{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=logistic";
Connection con= DriverManager.getConnection(url,"sa","");
return con;
}catch(SQLException e){
System.out.print(e);
throw e;
}
catch(NamingException e){
System.out.print(e);
throw e;
}
}提示exception javax.naming.NamingException is nobody of corresponding try statement
应该怎么改才对