在 Jdbc 中,当我查看表中的记录时,我得到 varible some value 1 和 variable some value wo 而不是值本身
我已经建立了java数据库连接,这是我的代码。我的问题是,当我从数据库查看记录时,即select * from recordtbl;
然后我没有得到这些变量中必须存在的值< code>Variable Filename =somevalue1;
variable checksumno =somevalue two;
代码是 -
package md5IntegrityCheck;
import java.sql.*;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
public class MD5IntegrityCheck
{
public static void main(String[] args)
throws UnsupportedEncodingException, NoSuchAlgorithmException
{
Connection con=null;
PreparedStatement pst=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:recordtbl","scott","tiger");
System.out.println("Step 1");
System.out.println(con.isClosed());
// get the file name here and store it in filename variable;
String filename="somevalueone ";
String chksumno="somevaluetwo";
System.out.println("Step 2");
pst=con.prepareStatement("insert into recordtbl values(?,?)");
//System.out.println(pst.isClosed());
System.out.println("Step3");
pst.setString(1,filename);
System.out.println("Step 4");
pst.setString(2,chksumno);
System.out.println("Step 5");
pst.execute();
System.out.println("Statement was EXECUTED!");
}
catch(Exception e)
{
System.out.println("ERROR : "+e);
}
if (args.length <= 0)
{
Md5Gui gui = new Md5Gui();
gui.runGui();
}
else
{
DoWork runningProgram = new DoWork();
runningProgram.run(args);
}
}
}
I have make java data base connectivity and here is my code.My problem is that when i view the record from database ie select * from recordtbl;
then I dont get the values that must be in these variable Varible Filename =somevalue1;
variable checksumno =somevalue two;
The code is -
package md5IntegrityCheck;
import java.sql.*;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
public class MD5IntegrityCheck
{
public static void main(String[] args)
throws UnsupportedEncodingException, NoSuchAlgorithmException
{
Connection con=null;
PreparedStatement pst=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:recordtbl","scott","tiger");
System.out.println("Step 1");
System.out.println(con.isClosed());
// get the file name here and store it in filename variable;
String filename="somevalueone ";
String chksumno="somevaluetwo";
System.out.println("Step 2");
pst=con.prepareStatement("insert into recordtbl values(?,?)");
//System.out.println(pst.isClosed());
System.out.println("Step3");
pst.setString(1,filename);
System.out.println("Step 4");
pst.setString(2,chksumno);
System.out.println("Step 5");
pst.execute();
System.out.println("Statement was EXECUTED!");
}
catch(Exception e)
{
System.out.println("ERROR : "+e);
}
if (args.length <= 0)
{
Md5Gui gui = new Md5Gui();
gui.runGui();
}
else
{
DoWork runningProgram = new DoWork();
runningProgram.run(args);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有执行
commit()
也没有关闭连接。尽管 JDBC 中的默认设置是autocommit=true
,规范非常清楚:此外,在没有提交的情况下,如果后面的代码打开不同的数据库连接,该连接可能看不到代码中早期的更新。在插入后添加
commit()
。You are not doing a
commit()
and also not closing the connection. Even though the default setting in JDBC isautocommit=true
, the spec is pretty clear:Also, without commit, if later code opens a different DB connection, that connection may not see the updates from earlier in the code. Add a
commit()
after the insert.像这样尝试一下。如果需要,请摆脱所有这些打印语句并使用调试器单步执行代码。
您正在连接到 Oracle 吗?如果是,为什么使用 ODBC 驱动程序而不是 Oracle 类型四、JDBC驱动?
Try it like this. Get rid of all those print statements and use a debugger to step through the code if you must.
Are you connecting to Oracle? If yes, why are you using an ODBC driver instead of an Oracle Type IV JDBC driver?