CREATE PROCEDURE SP_isUser@urId varchar(16),
@urPass varchar(16),
@urlResult int outputAS
SELECT @urlResult=count(*) FROM tbUser WHERE (urId=@urId) and (urPass=@urPass)
GO//java
Connection con=this.getConnection();
CallableStatement callableStatement=null;
int intResult=0;
try
{
callableStatement=con.prepareCall("{?=call SP_isUser(?,?)}");
callableStatement.setString(2, userName);
callableStatement.setString(3, password);
callableStatement.setInt(1,intResult);
callableStatement.execute();
if (callableStatement.getInt(3)>0)
{
return true;
}
else
{
return false;
}
@urPass varchar(16),
@urlResult int outputAS
SELECT @urlResult=count(*) FROM tbUser WHERE (urId=@urId) and (urPass=@urPass)
GO//java
Connection con=this.getConnection();
CallableStatement callableStatement=null;
int intResult=0;
try
{
callableStatement=con.prepareCall("{?=call SP_isUser(?,?)}");
callableStatement.setString(2, userName);
callableStatement.setString(3, password);
callableStatement.setInt(1,intResult);
callableStatement.execute();
if (callableStatement.getInt(3)>0)
{
return true;
}
else
{
return false;
}
解决方案 »
- FTP频繁上传抛出异常
- 谁有Apache MINA 中文API,给我传一份,谢谢了
- SQL 数据库 学习时需要注意哪些地方
- 几个JAVA的基本问题
- 在JCreator中如何做debug?
- 求救!帮帮忙!
- 关于中文显示问题
- 求救!SimpleIO.java:9: variable c might not have been initialized System.out.println("The letter is : "+c); ^ 1 error
- 如何判断JTree中一个结点是否已经展开?
- FutureTask类的handlePossibleCancellationInterrupt方法到底是干什么的?
- java applet 和使用的WEB 服务器有关?(急!在线等!)
- 一个小程序,想用线程实现在jpanel上搞出一行button,但是我的程序做出来后button不会动,程序改了三小时了,未果,请高指点江山
楼主【wufongming】截止到2008-06-26 21:13:59的历史汇总数据(不包括此帖):
发帖数:37 发帖分:1580
结贴数:36 结贴分:1480
未结数:1 未结分:100
结贴率:97.30 % 结分率:93.67 %
值得尊敬
public class ConnectionFactory implements DataSource
{
private String userName;
private String password;
private String driverName;
private String url;
private java.sql.Connection connection;
private Connection getNewConnection()
{
try
{
if (this.connection!=null)
{
this.connection.close();
this.connection=null;
}
Class.forName(this.driverName);
this.connection=DriverManager.getConnection(this.url,this.userName,
this.password);
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
return this.connection;
}
public Connection getConnection() throws SQLException
{
return this.getNewConnection();
} public Connection getConnection(String username, String password)
throws SQLException
{
this.setUserName(userName);
this.setPassword(password);
return this.getConnection();
} public PrintWriter getLogWriter() throws SQLException
{
// TODO Auto-generated method stub
return null;
} public int getLoginTimeout() throws SQLException
{
// TODO Auto-generated method stub
return 0;
} public void setLogWriter(PrintWriter out) throws SQLException
{
// TODO Auto-generated method stub } public void setLoginTimeout(int seconds) throws SQLException
{
// TODO Auto-generated method stub } public boolean isWrapperFor(Class<?> iface) throws SQLException
{
// TODO Auto-generated method stub
return false;
} public <T> T unwrap(Class<T> iface) throws SQLException
{
// TODO Auto-generated method stub
return null;
} /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub } /**
* @return the userName
*/
public String getUserName()
{
return userName;
} /**
* @param userName the userName to set
*/
public void setUserName(String userName)
{
this.userName = userName;
} /**
* @return the password
*/
public String getPassword()
{
return password;
} /**
* @param password the password to set
*/
public void setPassword(String password)
{
this.password = password;
} /**
* @return the driverName
*/
public String getDriverName()
{
return driverName;
} /**
* @param driverName the driverName to set
*/
public void setDriverName(String driverName)
{
this.driverName = driverName;
} /**
* @return the url
*/
public String getUrl()
{
return url;
} /**
* @param url the url to set
*/
public void setUrl(String url)
{
this.url = url;
}}
http://blog.csdn.net/net_lover/archive/2007/08/29/1764117.aspx
{
protected Connection connection=null;
protected ResultSet resultSet=null;
protected ResultSetMetaData resultSetMetaData=null;
private ConnectionFactory connectionFactory=null;
private java.sql.Statement statement=null;
private javax.sql.DataSource dataSource;
public DatabaseObject()
{
connection=null;
dataSource=null;
} public DatabaseObject(ConnectionFactory connectionFactory)
{
//this.set
}
public ResultSet getResultSet(String sql)
{
try
{
resultSet=statement.executeQuery(sql);
} catch (SQLException e)
{
e.printStackTrace();
this.resultSet=null;
}
return this.resultSet;
}
public ResultSetMetaData getResultSetMetaData(ResultSet resultSet)
{
ResultSetMetaData resultSetMetaData=null;
try
{
resultSetMetaData=resultSet.getMetaData();
} catch (SQLException e)
{
resultSetMetaData=null;
}
return resultSetMetaData;
}
public ResultSetMetaData getResultSetMetaData()
{
return (this.getResultSetMetaData(this.resultSet));
}
public ResultSet Execute(String spName)
{
ResultSet resultSet=null;
try
{
resultSet=statement.executeQuery(spName);
} catch (SQLException e)
{
System.out.print("執行錯誤:"+e.getMessage());
}
return resultSet;
}
public void setConnectionFactory(ConnectionFactory connectionFactory)
{
this.connectionFactory=connectionFactory;
try
{
connection=this.connectionFactory.getConnection();
statement=connection.createStatement();
} catch (SQLException e)
{
System.err.println(e);
}
}
public Connection getConnection()
{
return connection;
}
public java.sql.Statement getStatement()
{
return statement;
}
public javax.sql.DataSource getDataSource()
{
return dataSource;
}}
{
private final String dbDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String host;
private int port;
private String databaseName;
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub } public SqlServerConnectionFactory(String host, int port, String databaseName,
String userName,String password)
{
super();
this.host = host;
this.port = port;
this.databaseName = databaseName;
this.setUserName(userName);
this.setPassword(password);
this.init();
}
private void init()
{
super.setDriverName(dbDriver);
super.setUrl("jdbc:microsoft:sqlserver://"
+ host.trim() + ":"
+ new Integer(port).toString()
+ ";DatabaseName="
+ databaseName.trim());
}
public void setHost(String host)
{
if ((host==null)||host.equals("")||host.equals(".")||host.equals("local"))
{
host="localhost";
}
int index=host.indexOf("//",0);
if (index==0)
{
host=host.substring(2);
}
index=host.indexOf("//",0);
if (index>=0)
{
try
{
throw new Exception("SQL SERVER 主機名參數錯誤 !");
} catch (Exception e)
{
}
}
this.host=host;
}
public void setPort(int port)
{
if (port<0)
{
port=1433;
}
this.port=port;
}
public void setDatabaseName(String databaseName)
{
this.databaseName=databaseName;
}}
{ public DbObject()
{
super(new SqlServerConnectionFactory("xxx.vicp.net", 1433, "FSYH", "sa","stywa128ab"));
} public DbObject(ConnectionFactory connectionFactory)
{
super(connectionFactory);
// TODO Auto-generated constructor stub
}}
{
public String userName="";
public String password="";
public String encrypt="";
//private SqlServerConnectionFactory sqlServerConnectionFactory; public LoginDB()
{
super();
// TODO Auto-generated constructor stub
} public LoginDB(ConnectionFactory connectionFactory)
{
super(connectionFactory);
// TODO Auto-generated constructor stub
}
public void setUser(String userName)
{
this.userName=userName;
}
public void setPassWord(String passWord)
{
this.password=passWord;
}
public void setEncrypt(String encrypt)
{
this.encrypt=encrypt;
}
public boolean isUser()
{
Connection con=this.getConnection();
CallableStatement callableStatement=null;
int intResult=0;
try
{
callableStatement=con.prepareCall("{?=call SP_isUser(?,?)}");
callableStatement.setString(2, userName);
callableStatement.setString(3, password);
callableStatement.setInt(1,intResult);
callableStatement.execute();
if (callableStatement.getInt(3)>0)
{
return true;
}
else
{
return false;
}
} catch (Exception e)
{
return false;
}
}
public static void main(String[] args)
{
LoginDB loginDB=new LoginDB();
loginDB.setUser("wufongming");
loginDB.setPassWord("123456");
if(loginDB.isUser())
{
System.out.println(true);
}
else
{
System.out.println(false);
}
}
}
String reString="";
ResultSet resultSet=this.Execute("select urId from tbUser");
try
{
if(resultSet.next())
{
reString= resultSet.getString("urId");
}
}
catch(SQLException e)
{
e.printStackTrace();
}
return reString;
//callableStatement.setString(2,this.userName);
// callableStatement.setString(3,this.password);
//callableStatement.registerOutParameter(1, Types.INTEGER);
callableStatement.registerOutParameter("urResult", Types.INTEGER);
callableStatement.setString("urId", "wufongming");
callableStatement.setString("urPass","123456");
一執行到setString 就出錯。
Exception in thread "main" java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseCallableStatement.registerOutParameter(Ljava/lang/String;I)V
callableStatement.setString(2, userName);
callableStatement.setString(3, password);
callableStatement.setInt(1,intResult); 调用存储过程能这么写吗?我不清楚...望高人解答我只能说说我平时是怎么调用存储过程的...
http://topic.csdn.net/u/20080416/17/318670f0-d76d-4f12-82fc-c24cb5f7edbd.html
问题是现在我一,setString ,get,反正就是set,get 就出错.
Exception in thread "main" java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseCallableStatement
而用.set("urId","wufongming")
这种好象一直都不行,