stmt 出不来,是connection不到数据库吗?怎么破》

问题描述

packagevisual;importjava.awt.*;importjavax.swing.*;importjava.sql.*;importjava.awt.event.*;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassloginextendsJFrameimplementsActionListener{//Connectioncon=null;ResultSetrs=null;Statementstmt=null;//PreparedStatementps=null;Stringsql;privateJTextFieldtextField;privateJTextFieldtextField_1;privateJPasswordFieldpasswordField1;privateJButtonbutton;privateJButtonbutton_1;publiclogin(){setTitle("u5B66u751Fu767Bu9646u754Cu9762");getContentPane().setLayout(null);JLabellabel=newJLabel("u5B66u53F7uFF1A");label.setBounds(111,39,55,20);getContentPane().add(label);textField=newJTextField();textField.setBounds(176,38,137,20);getContentPane().add(textField);textField.setColumns(10);JLabellabel_1=newJLabel("u59D3u540DuFF1A");label_1.setBounds(111,69,55,18);getContentPane().add(label_1);textField_1=newJTextField();textField_1.setBounds(176,66,137,21);getContentPane().add(textField_1);textField_1.setColumns(10);JLabellabel_2=newJLabel("u5BC6u7801uFF1A");label_2.setBounds(111,100,55,18);getContentPane().add(label_2);passwordField1=newJPasswordField(10);passwordField1.setBounds(176,97,137,21);getContentPane().add(passwordField1);button=newJButton("u767Bu5F55");button.setBounds(176,128,66,21);button.addActionListener(this);getContentPane().add(button);button_1=newJButton("u64A4u56DE");button_1.setBounds(250,128,66,21);button_1.addActionListener(this);getContentPane().add(button_1);setSize(400,300);setVisible(true);}publicvoidactionPerformed(ActionEvente){StringstNo=textField.getText();Stringpsw=passwordField1.getText();sql="select学号,密码fromstudentwhere学号='"+stNo+"'and密码='"+psw+"'";try{connectionc=newconnection();stmt=c.getConnection().createStatement();System.out.println(stmt);//这里出不来,怎么破rs=stmt.executeQuery(sql);if(rs.next()){newAlreadylogin(stNo);this.setVisible(false);}elseJOptionPane.showMessageDialog(this,"用户名或密码错误");c.closeConnection();}catch(Exceptionex){}/*if(e.getActionCommand()=="u767Bu5F55"){if(textField.getText().equals("0001")&&textField_1.getText().equals("admin")){this.setVisible(false);newAlreadylogin();}else{JOptionPane.showMessageDialog(this,"用户名或密码错误");}}elseif(e.getSource()==button_1){this.setVisible(false);newAdmin1();}*/}publicstaticvoidmain(String[]args){//TODO自动生成方法存根newlogin();//re.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}/*privatevoidconnection(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundExceptionex){ex.printStackTrace();}try{con=DriverManager.getConnection("jdbc:odbc:test");}catch(SQLExceptionex){ex.printStackTrace();}}*/}

解决方案

解决方案二:
Connection这个是接口,你的代码就不能正常运行。建议你按照规范编码,类名大写.......。
解决方案三:
connectionc=newconnection();stmt=c.getConnection().createStatement();System.out.println(stmt);//这里出不来,怎么破这个connection类的getConnection()这个方法怎么写的??如果连接不到数据库当调用c.getConnection()时应该就会报错了!不知道这个方法你是怎么写的?你说的“这里出不来,怎么破”什么意思??是null吗?

时间: 2024-08-01 13:31:00

stmt 出不来,是connection不到数据库吗?怎么破》的相关文章

sqlconnection-老是抛出connection没被初始化,怎么破

问题描述 老是抛出connection没被初始化,怎么破 private void FrmSysLogin_Load(object sender, EventArgs e) { conStr = @"Data Source=2011-20131004OT;Initial Catalog=Bank;Integrated Security=true"; } private void btnLogin_Click(object sender, EventArgs e) { SqlConnec

c#-Connection Timeout Expired数据库偶尔会连接超时, 每小时会出现那么两三次

问题描述 Connection Timeout Expired数据库偶尔会连接超时, 每小时会出现那么两三次 Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was

ComboBox控件输入文本弹出下拉列表根据输入的文本在数据库查找~~

问题描述 ComboBox控件输入文本,显示下拉列表根据输入的文本在数据库模糊查找列表显示出查找的值.求大神解答给代码,小弟万分感谢. 解决方案 解决方案二:http://bbs.csdn.net/topics/300154879解决方案三:onchange事件中,根据内容区select数据集,然后遍历数据集,添加到items解决方案四:选择a,返回bprivatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){string

服务器-java.net.SocketException: Connection reset时出时不出

问题描述 java.net.SocketException: Connection reset时出时不出 最近写一个很简单的TCP通信的程序,问题的详细情况是这样的:服务器端在电脑上,客户端在android手机上,android手机连上学校里的无线可以正常连接.现在我用运行着服务器端的电脑上的360免费wifi开无线,android手机连上电脑开的这个无线再进行连接的时候就会抛出java.net.SocketException: Connection reset的错误!为什么呢?难道是TCP通信

【转载】JDBC中Connection解惑

本文转载自http://shift-alt-ctrl.iteye.com/blog/1967020   关于JDBC中关于Connection的两个疑问:   1.Connection实例是线程安全的吗?     即一个connection实例,在多线程环境中是否可以确保数据操作是安全的? Java代码   private static Connection connection;       上述代码,设计会不会有问题? 一个Connection实例,即对应底层一个TCP链接,有些开发者可能考

Connection reset by peer的常见原因

 Connection reset by peer的常见原因: 1)服务器的并发连接数超过了其承载量,服务器会将其中一些连接关闭:    如果知道实际连接服务器的并发客户数没有超过服务器的承载量,看下有没有网络流量异常.可以使用netstat -an查看网络连接情况. 2)客户端关掉了socket,而服务器还在给客户端发送数据:  这属于正常情况 3)防火牆的问题:    如果网络连接通过防火牆,而防火牆一般都会有超时的机制,在网络连接长时间不传输数据时,会关闭这个TCP的会话,关闭后在读写,就

jdbc- java.sql.SQLException: Closed Connection

问题描述 java.sql.SQLException: Closed Connection 我应该这么做? 解决方案 这意味着在某个时候成功地建立了连接,但是当你试图在那里提交时,连接已不再打开.您所提到的参数,如连接池设置.如果是这样,他们和这个问题无关.最有可能的原因是你和数据库之间的防火墙,是在一定量的空闲时间后杀死连接的.最常见的解决方法是使连接池运行验证查询,当一个连接被检查出来时.这将立即识别并驱逐死连接,确保你能很好的连接池的. 解决方案二: 这个是连接被异常关闭了,如果经常出现,

java.net.SocketException: Connection reset 解决方法_java

自从SEOTcs系统11月份24日更新了一下SEO得分算法以来,一直困扰我的一个问题出现了,java的数据job任务,在执行过程中会经常报以下的错误: "2011-12-03 18:00:32 DefaultHttpClient [INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error2011-12-03

Weblogic常见故障常:JDBC Connection Pools

WebLogic Server中数据库连接池是一个经常出问题的地方,总结一下出问题的原因和解决办法. 一.数据库连接泄漏 此类问题一般都是由于开发人员没有正确关闭数据库连接造成的.比如使用完Connection后,没有调用Connection.close()方法. 1.诊断方法 在Console中,找到Connection Pools Tab 和Diagnostics,设置以下属性(不同版本可能略有区别) Enable Connection Leak Profiling 启用连接池泄漏的监控.