我的java和oracle连接出了问题,帮忙看一下。代码是:
importjava.sql.*;publicclassTextJdbc{publicstaticvoidmain(String[]args)throwsExceptio...
import java.sql.*;
public class TextJdbc {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:CLRExtProc","scott","tiger");
}
}
错误信息是:Exception in thread "main" java.sql.SQLRecoverableException: 无法从套接字读取更多的数据
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1200)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1155)
at oracle.jdbc.driver.T4C8TTIpro.receive(T4C8TTIpro.java:128)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1064)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TextJdbc.main(TextJdbc.java:5)
用的驱动是oracle 11g 自带的,帮帮忙。 展开
public class TextJdbc {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:CLRExtProc","scott","tiger");
}
}
错误信息是:Exception in thread "main" java.sql.SQLRecoverableException: 无法从套接字读取更多的数据
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1200)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1155)
at oracle.jdbc.driver.T4C8TTIpro.receive(T4C8TTIpro.java:128)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1064)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TextJdbc.main(TextJdbc.java:5)
用的驱动是oracle 11g 自带的,帮帮忙。 展开
展开全部
没看出来错误,把我写的代码附上,希望能对你有点帮助吧
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnection {
/*
* 功能:编写一个静态方法用于与数据库建立连接
* 输入参数:无
* 返回值:数据库连接对象
* */
public static Connection getConnection(){
//定义一个连接对象
Connection conn=null;
//定义连接数据库的URL资源
String url="jdbc:oracle:thin:@192.168.3.9:1521:oracle";
//定义连接数据库的用户名称与密码
String username="faqsys";
String password="faqsysuser";
//加载数据库连接驱动
String className="oracle.jdbc.driver.OracleDriver";
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//获取数据库的连接对象
try {
conn=DriverManager.getConnection(url,username,password);
System.out.println("数据库连接建立成功...");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//返回连接对象
return conn;
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnection {
/*
* 功能:编写一个静态方法用于与数据库建立连接
* 输入参数:无
* 返回值:数据库连接对象
* */
public static Connection getConnection(){
//定义一个连接对象
Connection conn=null;
//定义连接数据库的URL资源
String url="jdbc:oracle:thin:@192.168.3.9:1521:oracle";
//定义连接数据库的用户名称与密码
String username="faqsys";
String password="faqsysuser";
//加载数据库连接驱动
String className="oracle.jdbc.driver.OracleDriver";
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//获取数据库的连接对象
try {
conn=DriverManager.getConnection(url,username,password);
System.out.println("数据库连接建立成功...");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//返回连接对象
return conn;
}
}
展开全部
oracle 11g的url应该是这个
你试试:
String userName="scott";
String password="tiger";
String url="jdbc:oracle:thin:@//localhos:1521/CLRExtProc";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(url, username, password);
你试试:
String userName="scott";
String password="tiger";
String url="jdbc:oracle:thin:@//localhos:1521/CLRExtProc";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(url, username, password);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我当初连接ORACLE时也无法连接,后来干脆连接的ACCESS。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-28
展开全部
首先,scott账户是默认无法使用的。请先通过oracle开起这个账户。
alter user scott account unlock;
指定密码
alter user scott identified by tiger
alter user scott account unlock;
指定密码
alter user scott identified by tiger
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询