请问我怎么连接不上数据库的池?
所有代码如下
import javax.naming.*;
import javax.naming.InitialContext;
import java.util.*;
import javax.sql.DataSource;
public class CP{
public static void main(String[] argv)
{
try{
InitialContext initialcontext = new InitialContext();
DataSource datasource = (DataSource)initialcontext.lookup ( "com.jdni.datasource ");
Connection connection = datasource.getConnection(); }
catch(Exception e)
{
}
}
}
出错
E:\> javac CP.java
CP.java:16: '} ' expected
}
^
CP.java:9: cannot resolve symbol
symbol : class InitialContext
location: class CP
InitialContext initialcontext = new InitialContext();
^
CP.java:9: cannot resolve symbol
symbol : class InitialContext
location: class CP
InitialContext initialcontext = new InitialContext();
^
CP.java:10: cannot resolve symbol
symbol : class DataSource
location: class CP
DataSource datasource = (DataSource)initialcontext.lookup( "com.jdni.data
source ");
^
CP.java:10: cannot resolve symbol
symbol : class DataSource
location: class CP
DataSource datasource = (DataSource)initialcontext.lookup( "com.jdni.data
source ");
^
CP.java:11: cannot resolve symbol
symbol : class Connection
location: class CP
Connection connection = datasource.getConnection();
^
6 errors
------解决方案--------------------import java.sql.*;
试试
------解决方案--------------------