调用代码如下:
import java.sql.*;
class MyOracle{
public static void main(String args[]) {
try{
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
String url="jdbc: oracle:thin: @127.0.0.1:5500: orcl";
Connection conn=DriverManager.getConnection(url,"user1","pass1");
CallableStatement c= conn.prepareCall("{call sumeng(?,?)}");
c.setString(1,"13");
c.setString(2, "xiaomao");
c.execute();
conn.close(); }
catch(Exception ex){
System.out.println(ex);
System.exit(0); }
}
}
报的异常为java.sql.SQLException: Io 异常: Bad packet type
不知道是什么原因,想高手请教~~
import java.sql.*;
class MyOracle{
public static void main(String args[]) {
try{
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
String url="jdbc: oracle:thin: @127.0.0.1:5500: orcl";
Connection conn=DriverManager.getConnection(url,"user1","pass1");
CallableStatement c= conn.prepareCall("{call sumeng(?,?)}");
c.setString(1,"13");
c.setString(2, "xiaomao");
c.execute();
conn.close(); }
catch(Exception ex){
System.out.println(ex);
System.exit(0); }
}
}
报的异常为java.sql.SQLException: Io 异常: Bad packet type
不知道是什么原因,想高手请教~~
public static Connection getConn() {
String URL = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String user = "user1";
String password = "pass1";
Connection connection = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(URL, user, password);
} catch (Exception err) {
err.printStackTrace();
return null;
}
return connection;
}
问题发现了,端口号不对,应该是String url="jdbc:oracle:thin:@127.0.0.1:1521:orcl",的确不
是我写的那个String url="jdbc:oracle:thin:@127.0.0.1:5500:orcl"。
另一个问题又出现了,我用浏览器登录数据库时使用的地址是http://127.0.0.1:5500/em,而不是http://127.0.0.1:1521/em 这个地方的端口号我试过不能使用1521,高手能解释下不?
em是个浏览器应用,跟你数据库的实际的jdbc端口当然不一样。那个5500就相当于你tomcat的端口8080,而你tomcat里面的实际连数据库就要用1521,一样啊。