java连接oracle出现问题 java.sql.SQLException: 违反协议
classes12.jar已经导入到lomboz程序如下importjava.sql.*;publicclassTestJDBC{publicstaticvoidmain...
classes12.jar已经导入到lomboz
程序如下
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:YYS", "scott", "tiger");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from dept");
while(rs.next()) {
System.out.println(rs.getString("deptno"));
System.out.println(rs.getInt("deptno"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
程序应当没错,是尚学堂马士兵老师的。
出错信息如下:
java.sql.SQLException: 违反协议
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:944)
at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:521)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:262)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:307)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestJDBC.main(TestJDBC.java:12)
---------------------
包导入了,oracle数据库版本90 导入的是classes12.jar 展开
程序如下
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:YYS", "scott", "tiger");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from dept");
while(rs.next()) {
System.out.println(rs.getString("deptno"));
System.out.println(rs.getInt("deptno"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
程序应当没错,是尚学堂马士兵老师的。
出错信息如下:
java.sql.SQLException: 违反协议
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:944)
at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:521)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:262)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:307)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestJDBC.main(TestJDBC.java:12)
---------------------
包导入了,oracle数据库版本90 导入的是classes12.jar 展开
6个回答
展开全部
package Test;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class db {
Connection conn=null;
static Statement st=null;
static ResultSet rs=null;
static String sql="SELECT * FROM infer ";
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
Connection conn = DriverManager.getConnection("jdbc:odbc:db02",null,null);
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString(1)+ " "+ rs.getString(2)+ " " +rs.getString(3)) ;
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class db {
Connection conn=null;
static Statement st=null;
static ResultSet rs=null;
static String sql="SELECT * FROM infer ";
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
Connection conn = DriverManager.getConnection("jdbc:odbc:db02",null,null);
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString(1)+ " "+ rs.getString(2)+ " " +rs.getString(3)) ;
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java.sql.SQLException: 违反协议
一般都是jdbc的驱动出问题了,你重新下个驱动试下吧
一般都是jdbc的驱动出问题了,你重新下个驱动试下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哪句报错?感觉可能是非法字符引起的,查看你数据库的字符集和记录里的字符。
System.out.println(rs.getInt("deptno"));也可能是这里,你的deptno有的不能转换成int类型。
System.out.println(rs.getInt("deptno"));也可能是这里,你的deptno有的不能转换成int类型。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
贴报错信息,不然没法看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用的oracle数据库是什么版本的啊 ?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询