English 中文(简体)
Java IDE 7.1至MSQ 2005, 采用撰写声明......返回地点?
原标题:Java IDE 7.1 to MS SQL 2005 Using PreparedStatement...wheres the return?

I have been toiling with this issue all day. After reading the benefits between Statements(S) and PreparedStatements(PS) I decided to convert all my S s to PS s in Netbeans. I was astounded to see that there were no errors but...no output from the execution of my code either.

import java.sql.*;
public class ViewingMySQL {
public static void main(String[] args) {

 //Declare Variables
 Connection con;
 ResultSet rs;
 Statement stmt;
 String sqlappname;

 PreparedStatement findAppID_lookup= null;
 String findAppID_lookup_stmt="select app.ID as APPID" 
 +" from IntergraphIN_AppTranslation" 
 +" inner    join app on app.unit=IntergraphIN_AppTranslation.UnitName" 
 +" where IntergraphIN_AppTranslation.IntergraphUnitName=(?)";

try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:odbc:database","username","password");
sqlappname=" XXXY01 ";
findAppID_lookup= con.prepareStatement(findAppID_lookup_stmt);
findAppID_lookup.setString(1, sqlappname);
rs = findAppID_lookup.executeQuery();

if(rs.next()){
System.out.println(rs.getInt("APPID"));
}

rs.close();
findAppID_lookup.close();

}
 catch(Exception e){
 System.err.println(e);
 }
}
}`

When the above code executes and builds...without output. run: BUILD SUCCESSFUL (total time: 1 second)

我原来是:

import java.sql.*;

public class ViewingMySQL {

public static void main(String[] args) {
//Declare Vars
Connection con;
ResultSet rs;
Statement stmt;
String sqlappname;

try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:odbc:Database","username","password");

sqlappname=" XXXY01 ";

stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                            ResultSet.CONCUR_READ_ONLY);

rs = stmt.executeQuery("SELECT ID FROM app where AppName="+sqlappname);
if(!rs.isBeforeFirst()){
    rs.close();
    rs = stmt.executeQuery("select app.ID from IntergraphIN_AppTranslation"
    +" inner join app"
    +" on app.unit=IntergraphIN_AppTranslation.UnitName"
    +" where IntergraphIN_AppTranslation.IntergraphUnitName="+sqlappname);
}

if(rs.next()){
System.out.println(rs.getInt(1));
}
rs.close();
stmt.close();
con.close();
}catch(Exception e){
System.err.println(e);
}
}
}`

This code outputs: run: 2020603 BUILD SUCCESSFUL (total time: 1 second)

见上文注1。

Can someone please help me with understanding what I m doing...is it the formatting of the variable that I m passing into the PS? Thanks, SCorliss

最佳回答

修改:

sqlappname=" XXXY01 ";

为此:

sqlappname="XXXY01";

最新资料:

编写国家具有多重利益。 例如:

  • 它可以帮助保护免受q的注射:投入受变数约束,投入不被用于编制说明。

  • 如果只有变数对变化产生影响(而不是改变 s单本身),则rd可能会使用 statement。

  • 发言可以更容易读到:你不必用引文等对我说几句话。

在这种情况下,援引的含义似乎被混淆。 原文:sqlappname= XXXY01“, 双重引用是宣布java String, 唯一引证是 s。 在准备的版本:Sqlappname=“XXXY01”,我们只是说,“这是约束的力量”,我们对我们具有约束力的准备声明表示怀疑。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签