首页 \ 问答 \ 将netbeans(JAVA)连接到MYSQL(Connecting netbeans (JAVA) to MYSQL)

将netbeans(JAVA)连接到MYSQL(Connecting netbeans (JAVA) to MYSQL)

问题是当我运行这段代码时,我总是得到答案COL12,而不是像我在MYSQL工作台中得到的所有数据列。 我需要得到相同的价值观。 此外,当我使用此查询“DELETE FROM test WHERE col1 = 2;”时 在netbeans我得到错误异常。

这是我在Netbeans中编写的代码。
包装箱;

import java.sql.*;  
import java.sql.Statement;
import java.sql.DriverManager;




public class Temp_Class {



public static void main(String[] args){

    try {

String query="SELECT * FROM test";
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=      DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root",  "19881990");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(query);
        rs.next();
        String sname= rs.getString(2);
 System.out.println(sname);
con.close();
    } catch (Exception e) {

            System.out.println("Error");

      }


    }



}

我在MYSQL Workbench中进行了表测试,其中columns =“col1,col2,col3”,其中values =“1,COL11,COL12”和“2,COL21,COL22”;

这是我用来删除DB中的值的代码。 。 。 但得到错误异常。

public static void main(String[] args){

    try {


        String deletesql="DELETE FROM test WHERE col1 = 2";

        Class.forName("com.mysql.jdbc.Driver");
        Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(select);

        Statement ds=con.createStatement();
        ResultSet dsrow=ds.executeQuery(deletesql);

        dsrow.next();
        String ds1= dsrow.getString(1);
        String ds2= dsrow.getString(2);
        String ds3= dsrow.getString(3);
        System.out.println(ds1+" "+ ds2+" "+ds3);

        con.close();
    } catch (Exception e) {

        System.out.println("Error");

    }


}

The problem is when I run this code, I always get answer COL12 instead of getting all the columns with data like I am getting in MYSQL workbench. I need to get same values. Moreover when I use this query "DELETE FROM test WHERE col1 = 2;" in netbeans I get Error Exception.

Here is my Code I wrote in Netbeans.
package sams;

import java.sql.*;  
import java.sql.Statement;
import java.sql.DriverManager;




public class Temp_Class {



public static void main(String[] args){

    try {

String query="SELECT * FROM test";
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=      DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root",  "19881990");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(query);
        rs.next();
        String sname= rs.getString(2);
 System.out.println(sname);
con.close();
    } catch (Exception e) {

            System.out.println("Error");

      }


    }



}

I have made table test in MYSQL Workbench, with columns="col1, col2, col3" with values="1, COL11, COL12" and "2, COL21, COL22";

This is the code I use to delete a value in DB. . . but getting Error Exception.

public static void main(String[] args){

    try {


        String deletesql="DELETE FROM test WHERE col1 = 2";

        Class.forName("com.mysql.jdbc.Driver");
        Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(select);

        Statement ds=con.createStatement();
        ResultSet dsrow=ds.executeQuery(deletesql);

        dsrow.next();
        String ds1= dsrow.getString(1);
        String ds2= dsrow.getString(2);
        String ds3= dsrow.getString(3);
        System.out.println(ds1+" "+ ds2+" "+ds3);

        con.close();
    } catch (Exception e) {

        System.out.println("Error");

    }


}

原文:
更新时间:2022-07-06 22:07

最满意答案

我猜这两个if语句中的一个正在评估为false:

    if image:
        if image.primary_image:
            url = images.get_serving_url(str(image.primary_image.key()))

如果您实际调用了get_serving_url,则可能会获得有效的服务URL或异常。 相反,url仍然有它的起始值,一个空字符串。


I would guess that one of these two if statements is evaluating to false:

    if image:
        if image.primary_image:
            url = images.get_serving_url(str(image.primary_image.key()))

If you were actually calling get_serving_url, you would either get a valid serving URL or an exception. Instead, url still has its starting value, a blank string.

相关问答

更多
  • 很简单,在TCPDF中引用图像时,不要使用/images/myimage.png等绝对链接 TCPDF不使用网站家庭结构,它使用基本操作系统目录结构。 因此,如果folde图像与tcpdf php文件位于同一文件夹中,请使用相关链接,例如:images / myimage.png。 或者../../ images/myimage.png如果它低于tcpdf文件夹。 我有同样的问题引用我的TTF字体文件。 应该很容易解决。 Simple, when referencing your image in TCPD ...
  • 假设图像URL在每个月都不一致,我会使用TFHpple,当应用加载时,解析DOM搜索@"//img"并从结果中提取src URL属性。 这个教程非常适合TFHpple。 Assuming the image URLs are not consistent from month to month I would use TFHpple and when the app loads, parse the DOM searching for @"//img" and pull the src URL attrib ...
  • 我已经用这种方式解决了 System.Windows.Size dimensions = ResolutionHelper.ScreenResolution; BitmapImage wb = new BitmapImage(); wb.SetSource(myStreamPhoto); ImgChosenPhoto.Source = wb; ImgChosenPhoto.Height = (int)dimensions.Height; ImgChosenPhoto.Width = (int)dime ...
  • 资源名称必须是正确的Java标识符。 称他们为card52至card52而不仅仅是他们的号码(如果我理解你的话)。 编辑添加:要将整数映射到正确的图像,您的代码应该管理映射本身。 一种(不是非常优雅)的方式是显式创建一个Bitmap[] cardImages = new Bitmap[52]; 数组并将每个资源分配到数组中,如例如 Resources r = context.getResources(); cardImages[0] = loadBitmap(r.getDrawable(R.drawable ...
  • 我修正了你的代码: var rotation = 0; function draw(){ var ctx = document.getElementById('myCanvas').getContext('2d'); ctx.globalCompositeOperation = 'destination-over'; ctx.save(); ctx.clearRect(0,0,200,200); ctx.translate(100,100); // to get it in the ...
  • 有关通过意图打开图像的信息,请参阅此主题,或者您可以查看此处 See this thread regarding opening image via intent or you can take a look over here
  • 说实话,我觉得你可能会采取一些错误的方法。 我个人会把这个图标作为CSS background-image附加到div。 之后,您可以在div的左侧应用填充等于图像的宽度(加上几个像素的间距)。 然后,您将能够使用background-position来执行以下操作: background-position:0px center; 这将为您提供我认为您所追求的更高程度的控制。 To be honest from your example I have a feeling you may be taking ...
  • 对于images/您已经检查了Linux上的权限,它将是755或777。 注意:您不需要绝对路径,您甚至可以在下面执行此操作。 $to = "images/".$_FILES['userfile']['name']; for images/ have you checked the Permission on Linux it will be 755 or 777. Note: You don't need absolute path for that you can even do like below ...
  • 路径 http://clicktravelnstay.com/img/photos/1344707033.png 返回404(未找到)。 您正在成功从数据库中提取图像名称,但实际的图像文件在您的服务器上不存在。 The path http://clicktravelnstay.com/img/photos/1344707033.png returns a 404 (not found). You're pulling the image name from the database successfully ...
  • 我猜这两个if语句中的一个正在评估为false: if image: if image.primary_image: url = images.get_serving_url(str(image.primary_image.key())) 如果您实际调用了get_serving_url,则可能会获得有效的服务URL或异常。 相反,url仍然有它的起始值,一个空字符串。 I would guess that one of these two if statem ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。